mongodb

Mongoose VersionError: No matching document found for id when document is being saved

非 Y 不嫁゛ 提交于 2021-02-18 13:01:18
问题 I am repeatedly seeing the following error when synchronizing a users cart through a "/sync/" API request. This is called whenever a user changes the contents of their shopping cart. VersionError: No matching document found for id "2y4b1hq601cd013e0af25e32" version 4 modifiedPaths "cart, cart.items, cart.updatedAt" at VersionError.MongooseError [as constructor] (/node_modules/mongoose/lib/error/mongooseError.js:13:11) at new VersionError (/node_modules/mongoose/lib/error/version.js:18:17) at

Is it possible to create a multi-select enum in mongoose

元气小坏坏 提交于 2021-02-18 12:32:07
问题 I have a model with an enum field, and currently documents can have any single value from the enum. I want documents to be allowed to have an array of values, but have mongoose enforce that all of the values are valid options that exist in the enum - is that possible? Essentially I want the equivalent of a HTML <select multiple> element instead of a <select> 回答1: Yes, you can apply an enum to a path that's defined as an array of strings. Each value will be passed to the enum validator and

How to store URL value in Mongoose Schema?

淺唱寂寞╮ 提交于 2021-02-18 11:45:08
问题 I am uploading the images from an IOS application to Firebase which returns to me the metadata including the URL of type URL . Should I store it of type String in the database like below code? or there is specific type for URL s? var schema = new Schema({ downloadURL: { type: String, createdDate: Date.now } }) 回答1: Well, As per the docs Monngoose doesn't have a schema type for URL. You could just use a string with RegExp to validate it or use some custome made type like this one var mongoose

How to toggle an element in array in mongoDB

社会主义新天地 提交于 2021-02-18 10:55:14
问题 I have an array of string ( ObjectIds ) in mongoDB. I want to toggle an element in that array: If that element exists in the array, remove it, otherwise push that element. Example: arr = ["5b608c0769698c3990c64ef3","5b608c0769698c3990c64ef4"] element = ["5b608c0769698c3990c64ef3"] Final array: arr = ["5b608c0769698c3990c64ef4"] My use-case: I am creating a blog website and in the Blog Schema I am storing the id of each user who has liked that blog, so that I can highlight the like button when

MongoDB: $or a full-text search and an $in

╄→гoц情女王★ 提交于 2021-02-18 10:43:13
问题 The problem Hi. I have what seems to me as a strange problem and I'm at a loss with it: Let's take: tags = [ ObjectId('a'), ObjectId('b') ] search = { $search: 'abc' } Now the following query works fine: db.entries.find({ $or: [ {$text:search} ] }) And this one too: db.entries.find({ $or: [ {tags:{$in:tags}} ] }) But combine them: db.entries.find({ $or: [ {$text:search}, {tags:{$in:tags}} ] }) And I get the following error: Unable to execute query: error processing query: ns=db.entries Tree:

MongoDB: $or a full-text search and an $in

别来无恙 提交于 2021-02-18 10:42:12
问题 The problem Hi. I have what seems to me as a strange problem and I'm at a loss with it: Let's take: tags = [ ObjectId('a'), ObjectId('b') ] search = { $search: 'abc' } Now the following query works fine: db.entries.find({ $or: [ {$text:search} ] }) And this one too: db.entries.find({ $or: [ {tags:{$in:tags}} ] }) But combine them: db.entries.find({ $or: [ {$text:search}, {tags:{$in:tags}} ] }) And I get the following error: Unable to execute query: error processing query: ns=db.entries Tree:

mongoose query same field with different values

 ̄綄美尐妖づ 提交于 2021-02-18 09:54:28
问题 Is there a way to user mongoose.find({title:'some title'}) to query the same field with multiple values? For example something like this mongoose.find({title:'some title', title:'some other title'}) sends back only documents matching title:'some other title is there a way to accomplish this ? 回答1: You should use the MongoDB $in operator - mongoose.find({title: {$in: ['some title', 'some other title']}}) You provide an array to $in operator and it will return all the documents which have an

mongoose query same field with different values

那年仲夏 提交于 2021-02-18 09:53:20
问题 Is there a way to user mongoose.find({title:'some title'}) to query the same field with multiple values? For example something like this mongoose.find({title:'some title', title:'some other title'}) sends back only documents matching title:'some other title is there a way to accomplish this ? 回答1: You should use the MongoDB $in operator - mongoose.find({title: {$in: ['some title', 'some other title']}}) You provide an array to $in operator and it will return all the documents which have an

how to clear warnings in node js while using mongoose

荒凉一梦 提交于 2021-02-18 09:35:42
问题 I'm having a doubt in The Web Developer Bootcamp course from section 29,304 module (node:15807) Warning: Accessing non-existent property 'count' of module exports inside circular dependency (Use node --trace-warnings ... to show where the warning was created) (node:15807) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency (node:15807) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency (node:15807) Warning

how to clear warnings in node js while using mongoose

老子叫甜甜 提交于 2021-02-18 09:29:32
问题 I'm having a doubt in The Web Developer Bootcamp course from section 29,304 module (node:15807) Warning: Accessing non-existent property 'count' of module exports inside circular dependency (Use node --trace-warnings ... to show where the warning was created) (node:15807) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency (node:15807) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency (node:15807) Warning