node.js - mongoose find not returning results when mongodb it does -


based on this question , this issue find faster findone if query not executed, i'm trying in node.js.

in mongodb (cli) i'm executing following command:

> db.carts.find({_id: objectid("57bd3df5c878685d3ec581d6")}).limit(1).count() 1 

then in node.js, using mongoose i'm using code returns 0:

const cartid = '57bd3df5c878685d3ec581d6'; const query = cart.find({ _id: new mongoose.types.objectid(cartid) }).limit(1); console.log(query.count()); // 0 

also noted if query executed returns cart:

query.exec().then(console.log); // [ { _id: 57bd3df5c878685d3ec581d6, __v: 0, ... 

here cart model:

const cartschema = new schema({     cartitems: [],     cartitemscount: { type: number, default: 0 },     carttotal: {         eur: {             value: { type: number, default: 0 },             currencyprec: { type: number, default: 2 },             count: { type: number, default: 0 },         },     },     carttotalineur: {         itemscost: { type: number, default: 0 },         shippingcost: { type: number, default: 0 },         discounts: {             quantity: { type: number, default: 0 },             percent: { type: number, default: 0 },             couponcode: string,         },         tax: { type: number, default: 0 },     },     shippinginfo: {         email: string,         receiver: string,         street: string,         postcode: string,         city: string,         country: {             name: string,             'alpha-2': string,             'alpha-3': string,             'sub-region-code': string,             'region-code': string,             'sub-region': string,             region: string,         },         isurgent: boolean,         issavedata: boolean,     },     created: { type: date, default: date.now },     updated: { type: date, default: date.now }, }); const cart = mongoose.model('cart', cartschema); 

am doing wrong?

i've never seen lowercase model name. shouldn't be:

const cart = mongoose.model('cart', cartschema); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -