mongoose

How can I delete a file with multer gridfs storage?

老子叫甜甜 提交于 2021-02-11 14:35:05
问题 The following code works as expected to upload and retrieve files: // Mongo URI const mongoURI = 'mongodbconnstring'; // // Create mongo connection const conn = mongoose.createConnection(mongoURI); // // Init gfs let gfs; conn.once('open', () => { gfs = new mongoose.mongo.GridFSBucket(conn.db, { bucketName: 'Uploads' }); }); // Create storage engine const storage = new GridFsStorage({ url: mongoURI, file: (req, file) => { return new Promise((resolve, reject) => { const filename = file

Mongoose and Typescript Model requirement function

血红的双手。 提交于 2021-02-11 14:02:30
问题 I am creating a model in typescript in mongoose and I would like to use a required function, however unlike normal javascript, I cannot use the 'this' operator as typescript doesn't recognize the scope. I would like to access the value of another one of the objects properties, but I am not sure how to do it. Here is what I am looking for: export interface IUser extends mongoose.Document { name: string; somethingElse?: number; }; export const UserSchema = new mongoose.Schema({ name: {type

Mongoose - Unable to create more than 4 fields using `findOrCreate`

落爺英雄遲暮 提交于 2021-02-11 14:01:02
问题 I am using Node.js, MongoDB with Mongoose and am using passport.js for authentication. Here is my user schema: const userSchema = new mongoose.Schema({ email: String, password: String, googleId: String, facebookId: String, profilePic: String, fName: String, lName: String }); And my google strategy: passport.use( new GoogleStrategy( { clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, callbackURL: "http://localhost:3000/auth/google/dashboard", profileFields: ["id",

Populate does not seem to populate for all the array elements

心不动则不痛 提交于 2021-02-11 13:54:54
问题 Consider the code below: const aux = await Fasta.find({}, "healthyTissue") .limit(1) .populate({ //---------------------first level (healthy or tumor fasta file) ---------------- path: "healthyTissue", model: "Hidden", options: { limit: 2 }, //--------------------- second level (hidden documents) ---------------- populate: { path: "children", options: { limit: 2 }, model: "FastaElement" } }); This is the output: The problem: just the first children is populated . I have double-checked the

Exclude nested field from encryption Mongoose encryption

邮差的信 提交于 2021-02-11 13:49:01
问题 So i am using an npm package called mongoose-encryption all is great except one important thing. I have an array called reports and it has alot of objects in it. Each object has one unique field called report_id the thing is i need to perform a delete operation based on that ID but if i encrypt it mongoose apparently cant find it. For that i excluded some fields like the docs said but i cant apparently exclude a nested field i tried this: usersSchema.plugin(encrypt,{secret:sigKey

How to update every document in collection based off another collection with Mongoose

只谈情不闲聊 提交于 2021-02-11 13:43:29
问题 I have a collection with a single document that contains many stats of different people. It is structured like so: // Stats list: [{ id: .... , lastUpdated: ... , stats: { Person1: {stat1: 0, stat2: 0, stat3: 0}, Person2: {stat1: 0, stat2: 0, stat3: 0}, ... Person100: {stat1: 0, stat2: 0, stat3: 0} } }] These stats are updated every 24 hours. Now I have a few hundred listings that contain a specific list of the people in the first collection. // Listings: [{ id: ..., persons: { Person1:

Getting NULL data from collection from MongoDB Atlas

﹥>﹥吖頭↗ 提交于 2021-02-11 13:41:43
问题 I have connected my code to MongoDB Atlas using Mongoose... even though the collection has a data in it its shows null in response. I want to know the exact issue and troubleshoot it, because the collection has the data required Collection details are in this image: 1. Connectivity Code - const mongoose = require('mongoose') const uri = "mongodb+srv://<user>:<password>@cluster0-3awwl.mongodb.net/"; mongoose.connect(uri, { dbName: 'bing_bot' }).catch((e) => { console.log('Database connectivity

Retrieve Mongoose Query Queue Time Metrics

久未见 提交于 2021-02-11 13:30:10
问题 In order to optimize the connection pool size, I thought it would make sense to graph query queue times. Is it possible to retrieve this metric from Mongoose? 回答1: See here for node monitoring. You need cmap events that apparently aren't documented there, see Ruby docs for example but they should be published by the node driver also. Track ConnectionCheckOutStarted and ConnectionCheckOutSucceeded and subtract the times to get the wait time. 来源: https://stackoverflow.com/questions/63652084

Retrieve Mongoose Query Queue Time Metrics

限于喜欢 提交于 2021-02-11 13:29:05
问题 In order to optimize the connection pool size, I thought it would make sense to graph query queue times. Is it possible to retrieve this metric from Mongoose? 回答1: See here for node monitoring. You need cmap events that apparently aren't documented there, see Ruby docs for example but they should be published by the node driver also. Track ConnectionCheckOutStarted and ConnectionCheckOutSucceeded and subtract the times to get the wait time. 来源: https://stackoverflow.com/questions/63652084

Mongoose .findOne() breaks when deployed

一个人想着一个人 提交于 2021-02-11 12:36:20
问题 I have Micro endpoints for my API that uses Mongoose. All of them work fine, except the one that uses .findOne(). This one returns the right data locally, but not when deployed to Now v2. Here is the endpoint: const { createError, run, send } = require("micro"); const mongoose = require("mongoose").set("debug", true); const mongooseConnect = require("./utils/mongooseConnect"); const Art = require("./schemas").art; mongooseConnect(); const art = async (req, res) => { console.log("hello world")