my current problem is with the db.collection.find() mongoose command. I'm relatively new to mongoose/mongodb, but I've gotten the hang of the concepts of it. Here is the test code I've been trying to run:
mongoose.connect(url);
function main()
{
var db = mongoose.connection;
db.on('open', function() {
db.collection('Tweet').find({id: 631460910368956400}, function (err, data){
console.log(data);
})
/*var coll = db.collection('Tweet');
db.collection('Tweet').findOne({id: 631460910368956400},function (err, ret) {
if(err) console.log(err);
console.log(ret['id']);
//db.close();
});*/
});
}
main();
The data returned from the non commented out field is a strange object:
{ connection: null,
server: null,
disconnectHandler:
{ s: { storedOps: [], storeOptions: [Object], topology: [Object] },
length: [Getter] },
bson: {},
ns: 'TEST.Tweet',
cmd: { find: 'TEST.Tweet', limit: 0, skip: 0, query: {}, slaveOk: false },
options:
{ skip: 0,
limit: 0,
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: false,
db:
{ domain: null,
_events: [Object],
_maxListeners: undefined,
s: [Object],
serverConfig: [Getter],
bufferMaxEntries: [Getter],
databaseName: [Getter],
etc etc... it goes on for much longer.
The IP address is a remote connection that successfully connects. I can do things like add and remove documents, but cannot actually view the documents from the javascript. I know that it is caused due to some kind of asynchronous problem, however I'm not sure how to fix it. Also, the commented out code for .findOne() seems to pull data completely fine in the code above.
What would be the problem with the code for the .find() function? An explanation for why the current error in data retrieving would be great also.
Thanks for your help!