2

I have the following query where the oids is an array of object id's.

users.find({ _id: { $in: oids } }, function(err, result){
    console.log(result);
}); 

I expect a list of users where the id from the users are in the array of object id's, but the actual result looks like this:

{ db: { databaseName: 'users', serverConfig: { _callBackStore: [Object], host: 'localhost', port: 27017, options: [Object], internalMaster: true, connected: true, poolSize: 5, disableDriverBSONSizeCheck: false, slaveOk: undefined, _used: true, replicasetInstance: null, ssl: false, sslValidate: false, sslCA: null, sslCert: undefined, sslKey: undefined, sslPass: undefined, _readPreference: null, socketOptions: [Object], logger: [Object], eventHandlers: [Object], _serverState: 'connected', _state: [Object], recordQueryStats: false, db: [Circular], dbInstances: [Object], connectionPool: [Object], isMasterDoc: [Object] }, options: { w: 1 }, _applicationClosed: false, native_parser: undefined, bsonLib: { Code: [Function: Code], Symbol: [Function: Symbol], BSON: [Object], DBRef: [Function: DBRef], Binary: [Object], ObjectID: [Object], Long: [Object], Timestamp: [Object], Double: [Function: Double], MinKey: [Function: MinKey], MaxKey: [Function: MaxKey] }, bson: {} ... and so on ...

If I use user.findOne(...) the result is the expected user, but I like to query all users in the array.

1 Answer 1

1

find() method returns you a cursor, so 'result' is printing all the cursor details. I guess you have to do something like:

collection.find().toArray(function(err, results) {
     test.assertEquals(1, results.length);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.