2

what i want, is to only return the _id and data in meta (not my field, but since mongoose has this prime example): mongoose embedd documents doc

so, i'm not looking for any _id in particular, i'm looking for records with meta.votes.length > 0 or meta.fans.length > 0. currently i do:

Model.find({}, ['_id','meta'], function (err, data) { callback(null, data); });

i get records with no /data/. i guess an alternative to not finding these sets would be a way to filter them out?

EDIT: i have temporarily resolved my issue with:

use : { type: Boolean, default: 1 },

though this might be a feature (showing and hiding results - old data for instance), i don't consider this a /solution/.

1 Answer 1

1

Well meta.votes and meta.fans are both just Number objects so I don't think you want meta.fans.length just access them directly like an int.

This query should retrieve just the _id and meta information for votes > 0

Model.find({ "meta.votes" : { $gt : 0 } }, ['_id','meta']).exec(function(err, data) {
   callback(null, data);
});

And this query should retrieve just the _id and meta information for fans > 0

Model.find({ "meta.fans" : { $gt : 0 } }, ['_id','meta']).exec(function(err, data) {
   callback(null, data);
});

And you could pull both queries together like this:

Model.find({ $or : [ { "meta.votes" : { $gt : 0 } },
                     { "meta.fans" : { $gt : 0 } } ] }, ['_id','meta']).exec(function(err, data) {
   callback(null, data);
});

You should be seeing returns like: { _id: 5001b3ce7cf4b534a3000002, meta: { votes: 1, fans: 1 } }

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.