How to exclude one particular field from a collection in Mongoose?

Use query.select for field selection in the current (3.x) Mongoose builds. Prefix a field name you want to exclude with a -; so in your case: Query.select(‘-Image’); Quick aside: in JavaScript, variables starting with a capital letter should be reserved for constructor functions. So consider renaming Query as query in your code.

Mongoose ‘static’ methods vs. ‘instance’ methods

statics are the methods defined on the Model. methods are defined on the document (instance). You might use a static method like Animal.findByName: const fido = await Animal.findByName(‘fido’); // fido => { name: ‘fido’, type: ‘dog’ } And you might use an instance method like fido.findSimilarTypes: const dogs = await fido.findSimilarTypes(); // dogs => [ … Read more

Mongoose limit/offset and count query

I suggest you to use 2 queries: db.collection.count() will return total number of items. This value is stored somewhere in Mongo and it is not calculated. db.collection.find().skip(20).limit(10) here I assume you could use a sort by some field, so do not forget to add an index on this field. This query will be fast too. … Read more