mongoose-schema

How do I delete an item from a Schema which is an array of objects in mongoose?

孤人 提交于 2020-04-30 08:46:49
问题 I want to delete a resume from list of resumes in my schema. I'm using mongoose(5.9.7) and express js. Schema const ResumeSchema = new Schema({ user: { type: Schema.Types.ObjectId, ref: "User" }, fileLink: { type: String, required: true }, fileName: { type: String, required: true }, description: { type: String, required: true } }); module.exports = Resume = mongoose.model("Resume", ResumeSchema); I have a route to fetch all the resumes. I'm creating a ref of resume in my ProfileSchema as well

mongodb + group by with multiple collections

99封情书 提交于 2020-04-17 22:05:50
问题 I have 3 to 4 collections users payments branches grades In users table we have multiple types of users like student, parents like this. In payments table user payments details have payments details with partical amount or full amount. In branches, table have branch details. I am trying find the reports based on branches and grades wise. total numbers of users in that branch total numbers of paid users in that branch based on paidStatus column. total sum amount recieved in that branch based

mongodb + group by with multiple collections

一世执手 提交于 2020-04-17 22:05:17
问题 I have 3 to 4 collections users payments branches grades In users table we have multiple types of users like student, parents like this. In payments table user payments details have payments details with partical amount or full amount. In branches, table have branch details. I am trying find the reports based on branches and grades wise. total numbers of users in that branch total numbers of paid users in that branch based on paidStatus column. total sum amount recieved in that branch based

nested ref to populate mongoose 5.0 nodejs

戏子无情 提交于 2020-02-06 08:24:27
问题 I have two models. The first one is UserSchema and the second one is CategorySchema var UserSchema = Schema({ firstName: { type: String, required: true }, secondName: String, lastName: { type: String, required: true }, email: { type: String, unique: true, required: true }, password: { type: String, required: true }, status: { type: String, required: true }, roles: [{ type: Schema.ObjectId, ref: 'Role' }], publications: [{ title: { type: String, }, description: String, status: { type: String,

How to select specific field in nested populate in mogoose

旧时模样 提交于 2020-01-23 04:55:29
问题 here is my schema: var UserSchema = new Schema({ email: String, name: String, city: String, username: String, profilePic: String, phoneNo: Number, shortList: { project: [{ type: Schema.ObjectId, ref: "Project" }], flat: [{ type: Schema.ObjectId, ref: "Flat" }], }, }); var FlatSchema = new Schema({ project: { type: Schema.ObjectId, ref: "Project" }, status: String, floor: Number, size: String, type: String, flat_number: String, price: Number, flooringType: String, createdAt: { type: Date,

Easy way to increment Mongoose document versions for any update queries?

扶醉桌前 提交于 2020-01-22 19:36:45
问题 I want to start taking advantage of Mongooses document versioning (__v key). I was having an issue actually incrementing the version value, then I found that you have to add this.increment() when executing a query. Is there a way to have automatically incremented? For now, I just added it to the pre middleware for a update-type queries: module.exports = Mongoose => { const Schema = Mongoose.Schema const modelSchema = new Schema( { name: Schema.Types.String, description: Schema.Types.String }

MongoDB : How to multiply a field that appears only in $project?

≡放荡痞女 提交于 2020-01-21 19:13:10
问题 I'm joining ($lookup) two collection the following way : const LEAD_PRICE = ....; // doesn't matter Client.aggregate( [ { $lookup: { from: "clientboughtleads", localField: "_id", foreignField: "Client", as: "ClientLeads" } }, { $project: { ClientId: "$_id", RegistrationDate: "$date", TotalPurchasedLeads: { $size: "$ClientLeads" }, IncomeFromClient: { // This one is always undefined $multiply: [LEAD_PRICE / 2, "$TotalPurchasedLeads"] } } } ] I want to calculate IncomeFromClient by the mul of a

MongoDb + Mongoose | How to hash array of passwords instead of a single password

房东的猫 提交于 2020-01-16 09:11:44
问题 I have a json array containing data of almost 300 users. I am using (Mongoose)Model.InsertMany() for saving user data array to Mongodb. To hash a single user password i am using this guide: https://www.mongodb.com/blog/post/password-authentication-with-mongoose-part-1 but i want to hash passwords of all users at once. This guide uses 'save' function to hash but as i am using 'InsertMany()' to dump to Mongodb so how can i achieve hashing by using InsertMany() 回答1: You can use pre save hook in

MongoDb + Mongoose | How to hash array of passwords instead of a single password

天大地大妈咪最大 提交于 2020-01-16 09:11:08
问题 I have a json array containing data of almost 300 users. I am using (Mongoose)Model.InsertMany() for saving user data array to Mongodb. To hash a single user password i am using this guide: https://www.mongodb.com/blog/post/password-authentication-with-mongoose-part-1 but i want to hash passwords of all users at once. This guide uses 'save' function to hash but as i am using 'InsertMany()' to dump to Mongodb so how can i achieve hashing by using InsertMany() 回答1: You can use pre save hook in

Nodejs mongoose select objects with in nested arrays based on object properties

走远了吗. 提交于 2020-01-06 08:16:47
问题 I'm new to nodejs and currently i'm trying to implement a web application using nodejs and mongodb (mongoose). I want to select objects within a nested array and parent array based on a property of those objects. Simply - I need to select Categories which are having valid property as true and sub_services which are having valid property as true. (with in a category there cannot be sub_services which having valid property as false and there cannot be category objects which are having valid