2

Pretty new to mongo and mongoose.

I have

var mongoose = require('mongoose'), errorHandler = require('./errors'), ClientSummary = mongoose.model('ClientSummary'); exports.list = function(req, res) { ClientSummary.find().sort('-LastName').exec(function(err, clients) { if (err) { return res.status(400).send({ message: errorHandler.getErrorMessage(err) }); } else { console.log(clients); res.jsonp(clients); } }); }; 

this returns double results for each client

I copied this from the console

[ { _id: '_?\u0007Z?WM???3\u0016?\u0017', ArchivedDate: Sun Dec 31 0 18:00:00 GMT-0600 (Central Standard Time), ArchiveDate: Sat Nov 08 2014 17:18:55 GMT-0600 (Central Standard Time), Archived: false, Phone: null, EmailAddress: '[email protected]', LastName: 'test', FirstName: 'test' }, { _id: '??\u0002otsF???\u000fF\u0010\u0019\n', ArchivedDate: Sun Dec 31 0 18:00:00 GMT-0600 (Central Standard Time), ArchiveDate: Sat Nov 08 2014 17:18:55 GMT-0600 (Central Standard Time), Archived: false, Phone: null, EmailAddress: '[email protected]', LastName: 'test', FirstName: 'test' } ] 

I get this from a query

db.clients.find() { "_id" : BinData(4,"U/UnaPQyRxqtc1iPJP7Lyw=="), "Contact" : { "FirstName" : "test", "LastName" : "test", "EmailAddress" : "[email protected]", "Phone" : null, "PhoneSecondary" : null }, "Address" : null, "Source" : null, "SourceNotes" : "asdf", "Archived" : false, "ArchivedDate" : ISODate("0001-01-01T00:00:00Z"), "StartDate" : ISODate("0001-01-01T00:00:00Z") } 

any thoughts would be greatly appreciated

Thanks,

Raif

1 Answer 1

2

I do not see why you are saying that you have duplicate results in the first query. The _ids are different, so, it looks like there are two different objects.

Further, I also think that the second query that you have refers to a different collection; i.e. clients, while the first query refers to the collection clientsummary.

For example, use the mongo shell, connect to the db *, and try the following two:

> show collections 

If I am right, you have both clients and clientsummary as collections in your db. Then, also try

> db.clientsummary.count() 

This should return 2.

Note, that it might be the case that you have clientSummary instead of clientsummary as collection in your db, or even clientsummarys/clientSummarys or clientsummaries/clientSummaries as mongo/mongoose will use the plural for the collection and an s is usually attached in the end of the word referring to the collection. Just use the right name.

(*) You can connect to the db mydb (where the collections you are referring to can be found) using the command:

$ mongo --shell localhost/mydb 

(Assuming you have mydb on localhost.)

Sign up to request clarification or add additional context in comments.

3 Comments

christ have mercy. I blame the screaming kids. How embarrassing. Ok, I"m going to mark yours as the correct answer, but then I'm going to try to delete this to erase the evidence
Hey, it can happen to anyone. Especially if you are new to mongo/mongoose. No worries.
Same issue for me but slightly different cause. I was using mongoimport (grunt task) to upload the data but wasn't dropping the database before adding in the items. Every time I ran the grunt task, it would add a dupe.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.