mongodb

How to exclude null values from Mongoose populate query

僤鯓⒐⒋嵵緔 提交于 2021-02-19 01:55:04
问题 I am building an app and I have create 2 models. const UserSchema = new Schema({ _id: Schema.Types.ObjectId, account:{ type: String, unique: true }, email: String, first_name: String, last_name: String } const VenueSchema = new Schema({ _id: Schema.Types.ObjectId, venue_type: String, capacity: Number }) and const MediatorSchema = new Schema({ _id: Schema.Types.ObjectId, account:{ type: String, unique: true }, user: {type: Schema.Types.ObjectId, ref:'User' } venue: {type: Schema.Types.ObjectId

Strapi is not loading the Collections from existing MongoDB hosted on Digital Ocean

让人想犯罪 __ 提交于 2021-02-19 01:24:39
问题 I am creating a New Application using Strapi and I have tried to connect it with my MongoDB which is hosted on Digital Ocean but unfortunately Strapi is not able to fetch the collections from existing MongoDB . Here, I am mentioning the complete steps that I have followed to achieve the connection of Strapi with the existing MongoDB: I have followed this guide step by step to create a Strapi Application: Quick_Start_Strapi Although, I need to connect to my existing MongoDB which is hosted on

Mongoosejs refresh a document

丶灬走出姿态 提交于 2021-02-19 01:21:17
问题 Suppose I have a document for example: var doc = Model.findOne({name:"name"}); Now if the document gets edited trough another connection the the database, doc doesn't hold the right information. I do need it, so I have to "refresh" or "redownload" it from the database. Is there any way to do this with only the object "doc"? 回答1: Assuming doc contains the document instance to refresh, you can do this to generically refresh it: doc.model(doc.constructor.modelName).findOne({_id: doc._id},

Mongoosejs refresh a document

十年热恋 提交于 2021-02-19 01:20:51
问题 Suppose I have a document for example: var doc = Model.findOne({name:"name"}); Now if the document gets edited trough another connection the the database, doc doesn't hold the right information. I do need it, so I have to "refresh" or "redownload" it from the database. Is there any way to do this with only the object "doc"? 回答1: Assuming doc contains the document instance to refresh, you can do this to generically refresh it: doc.model(doc.constructor.modelName).findOne({_id: doc._id},

mongodb query result without field name

ぐ巨炮叔叔 提交于 2021-02-19 01:06:42
问题 Is there a way to get mongodb query results with only the values and not the field names. My query gives me the following result: { "t_number" : 2508 }, { "t_number" : 2560 }, { "t_number" : 2599 } Ideally I want the query result to be [2508,2560,2599] . Or if that is not possible, is it possible to get the query result as [{2508},{2560},{2599}] . I know that I can iterate over the result and change the format in my programming language. I am looking for a way to get that from mongodb and

MongoDB/Mongoose index make query faster or slow it down?

梦想与她 提交于 2021-02-19 01:06:28
问题 I have an article model like this: var ArticleSchema = new Schema({ type: String ,title: String ,content: String ,hashtags: [String] ,comments: [{ type: Schema.ObjectId ,ref: 'Comment' }] ,replies: [{ type: Schema.ObjectId ,ref: 'Reply' }] , status: String ,statusMeta: { createdBy: { type: Schema.ObjectId ,ref: 'User' } ,createdDate: Date , updatedBy: { type: Schema.ObjectId ,ref: 'User' } ,updatedDate: Date ,deletedBy: { type: Schema.ObjectId, ref: 'User' } ,deletedDate: Date ,undeletedBy: {

MongoDB/Mongoose index make query faster or slow it down?

妖精的绣舞 提交于 2021-02-19 01:06:16
问题 I have an article model like this: var ArticleSchema = new Schema({ type: String ,title: String ,content: String ,hashtags: [String] ,comments: [{ type: Schema.ObjectId ,ref: 'Comment' }] ,replies: [{ type: Schema.ObjectId ,ref: 'Reply' }] , status: String ,statusMeta: { createdBy: { type: Schema.ObjectId ,ref: 'User' } ,createdDate: Date , updatedBy: { type: Schema.ObjectId ,ref: 'User' } ,updatedDate: Date ,deletedBy: { type: Schema.ObjectId, ref: 'User' } ,deletedDate: Date ,undeletedBy: {

MongoDB/Mongoose index make query faster or slow it down?

天大地大妈咪最大 提交于 2021-02-19 01:05:46
问题 I have an article model like this: var ArticleSchema = new Schema({ type: String ,title: String ,content: String ,hashtags: [String] ,comments: [{ type: Schema.ObjectId ,ref: 'Comment' }] ,replies: [{ type: Schema.ObjectId ,ref: 'Reply' }] , status: String ,statusMeta: { createdBy: { type: Schema.ObjectId ,ref: 'User' } ,createdDate: Date , updatedBy: { type: Schema.ObjectId ,ref: 'User' } ,updatedDate: Date ,deletedBy: { type: Schema.ObjectId, ref: 'User' } ,deletedDate: Date ,undeletedBy: {

how to update nested object of mongoose document for only provided keys

佐手、 提交于 2021-02-18 22:41:32
问题 I am going to update some fields of mongoose document according to provided keys. For example, When we present mongoose document in json. user: { address: { city: "city" country: "country" } } And update params is given like this. address: { city: "city_new" } when I run the mongoose api like this. let params = { address: { city: "city_new" } } User.set(param) It replace whole address object and final result is user: { address: { city: "city_new" } } it just replace address field, but I want

how to update nested object of mongoose document for only provided keys

十年热恋 提交于 2021-02-18 22:41:08
问题 I am going to update some fields of mongoose document according to provided keys. For example, When we present mongoose document in json. user: { address: { city: "city" country: "country" } } And update params is given like this. address: { city: "city_new" } when I run the mongoose api like this. let params = { address: { city: "city_new" } } User.set(param) It replace whole address object and final result is user: { address: { city: "city_new" } } it just replace address field, but I want