Get Object has no method 'executeDbCommand' - node.js

I am using mongodb 3.0.2 with mongoose 4.0 in nodejs
While i upgrade mongoose 2.3 to 4.0 it started to throw error for
'executeDbCommand', it looks like this is deprecated in mongoose 4.0,
anyone has an idea for replacement of this command ?
I tried to dig into the mongoose but cant find it, Please help me if anyone knows !!

Mongoose uses a native driver in itself prototype, and api docs says that native drive has a command method. The code will be:
var db = mongoose.createConnection('mongodb://user:pass#localhost:port/database');
db.command('sample command');

Related

Mongoose 4 to 5: connection.db.collection() undefined

I'm attempting to upgrade from Mongoose 4.x to 5.x. So far the biggest issue I'm running in to is after the database has connected I'm unable to fetch collections like I was able to in 4.x.
const someCollection = mongoose.connection.db.collection('someCollection');
This code works fine in 4.x, but apparently the underlying structure of Mongoose has changed between versions.
Is there an equivalent way to do this in Mongoose 5.x? I looked in the documentation and the migration guide but didn't see anything.
For Mongoose 5.x, the .db part isn't needed so it should be:
mongoose.connection.collection('someCollection');

Mongodb query to node.js format

db.gpsvalues.aggregate([
{$sort:{"Timestamp":1}},
{$group:{
"_id":"$EmpID",
LastUpdated:{$last:"$Timestamp"},
Latitude:{$last:"$Latitude"},
Longitude:{$last:"$Longitude"}
}}
])
this is the query which returns expected value in mongodb. but i want to get the same values from node.js api call?
can someone tell me how to make the node.js api?
thanks in advance
You may check the mongojs node.js client which supports aggregation as mentionned in the manual.
I personnally have not used this feature yet but it should work as expected.

nodejs mongodb driver and GridFS

I'm using nodejs and the native mongodb driver v2.0.43 (latest as of 9/18/2015) and am having problems querying the db.fs.files collection. It is returning that fs is undefined yet I can use the mongo console and see the files that have been stored using db.fs.files.find().toArray(). Does anyone have any experience querying the db.fs.files collection via node using the mongodb driver?
thanks
Ben
Ok, after doing a better google query I found this solution: Can you use find queries on GridFS using javascript API?
The gist is you have to use 'fs.files' as the collection name.
db.collection('fs.files').find().toArray();

Validating array items with joi in a Foxx app

I am having problems with using joi array-item validation in foxx applications as well as the arango-shell with arangodb-2.5.5.
The joi-documentation suggests to use something like:
var Joi = require('joi');
Joi.array().items({'name': Joi.string().required()});
for validating a dataset similar to:
[{'name': 'Peter'}, {'name': 'Edeltraut'}, ...]
However, using it in a Foxx application results in the application to stop working. Pasting the snippet from above into the arango-shell produces the following output:
JavaScript exception: TypeError: undefined is not a function
!Joi.array().items({'name': Joi.string().required()});
! ^
stacktrace: TypeError: undefined is not a function
at <shell command>:1:13
Is there something I am missing, or is arangodb using a modified / smaller version of joi that has this feature stripped out?
ArangoDB 2.5 uses an older version of joi. The method in question was renamed to items in joi 6.0 and was previously called includes.
You can find the documentation for joi 4.9.0 (the version shipped with ArangoDB 2.5) at https://github.com/hapijs/joi/tree/v4.9.0
ArangoDB 2.6 will ship with joi 6.4.3, which is the latest version at this time.
If you want to know the version of an NPM dependency shipped with ArangoDB, you can also find out the version number by importing its package.json file like this:
require('joi/package.json').version
You don't have to wait for ArangoDB 2.6 to use the latest version of joi. If you npm install joi --save inside of your Foxx app's APP folder, it'll be used instead of the one bundled with ArangoDB. I've been doing that for a while now.

How to get DB object in SailsJS / Waterline adapter methods?

I am trying to write a SailsJS / Waterline adapter for OrientDB using Oriento module for NodeJS.
I am able to understand the basics of Waterline adapter interface using boilerplate adapter code for SailsJS but not sure how to get hold of DB object in adapter methods. I am sure DB object is created and maintained by SailsJS or Waterline but how to get an access to it in adapter's methods as without DB object, I will not be able to make call to OrientDB. Look for code samples in Oriento module to know how to call OrientDB from NodeJS.
I will appreciate if some one can show some example code of getting DB object in adapter's method - define(), describe(), drop(), find() etc.
We're unfamiliar with Sails, but looks like the _dbPools private variable is what you're looking for - https://github.com/balderdashy/sails-adapter-boilerplate/blob/master/index.js#L59

Resources