mongoose

Passport authentication callback hangs

偶尔善良 提交于 2021-02-10 04:35:52
问题 After hours trying to solve this by myself I reach to SO community looking for some light. I'm using passport for user authentication. It's already initialized in my main express.js file as per the docs: app.use(passport.initialize()); I got a index.js file which handles facebook-passport in this manner: Index.js 'use strict'; import express from 'express'; import passport from 'passport'; import auth from '../auth.service'; let router = express.Router(); //this function is defined in the

MongoError: pool is draining, new operations prohibited when using MongoMemoryServer in integration test

情到浓时终转凉″ 提交于 2021-02-09 11:47:33
问题 I'm using MongoMemoryServer to write an integration test. I have two integration test files. When I run the IT tests I see the following. I don't understand why. I'm using jestjs test framework. I'm seeing the following error when I have two IT test files MongoError: pool is draining, new operations prohibited 37 | for (const key in collections) { 38 | const collection = collections[key]; > 39 | await collection.deleteMany(); | ^ 40 | } 41 | }; Here is my setup //db-handler.js const mongoose

Mongoose's loadClass() with TypeScript

六月ゝ 毕业季﹏ 提交于 2021-02-09 10:59:31
问题 Mongoose accepts an ES6 class as the basis for a schema. The example from that link: class PersonClass { get fullName() { return `${this.firstName} ${this.lastName}`; // compiler error } } PersonSchema.loadClass(PersonClass); The schema's properties are not defined in the class, so the TypeScript compiler says: Property firstName does not exist on type PersonClass. A hack is to use a dummy constructor: constructor(readonly firstName: string, readonly lastName: string) { } However that is hack

Mongoose rename collection

我们两清 提交于 2021-02-09 07:15:17
问题 I am trying to make db.collection.renameCollection with mongoose, but i can't find that function anywhere. Did they miss to add it or i am looking at wrong place? As quick example of what i am doing is: var conn = mongoose.createConnection('localhost',"dbname"); var Collection = conn.model(collectionName, Schema, collectionName); console.log(typeof Collection.renameCollection); Which show undefined. var con = mongoose.createConnection('localhost',"dbname"); con.once('open', function() {

Mongoose rename collection

送分小仙女□ 提交于 2021-02-09 07:13:44
问题 I am trying to make db.collection.renameCollection with mongoose, but i can't find that function anywhere. Did they miss to add it or i am looking at wrong place? As quick example of what i am doing is: var conn = mongoose.createConnection('localhost',"dbname"); var Collection = conn.model(collectionName, Schema, collectionName); console.log(typeof Collection.renameCollection); Which show undefined. var con = mongoose.createConnection('localhost',"dbname"); con.once('open', function() {

Nodejs mongodb dynamic collection name

浪尽此生 提交于 2021-02-09 07:13:12
问题 I have several mongodb collections, Fruits: [ {}, {}, {} ...], Bread: [{}, {}, {} ...] I want to use dynamic collection name in my server like // :collection will be "Fruits" or "Bread" app.get('/fetch/:collection', function (req, res){ [req.params.collection].find({}, function(err, docs){ res.json(docs) }) }) But as you know, [req.params.collection].find()... isn't working. How can I use dynamic collection name? 回答1: This is not working as the collection name you are passing is just a

Nodejs mongodb dynamic collection name

∥☆過路亽.° 提交于 2021-02-09 07:10:35
问题 I have several mongodb collections, Fruits: [ {}, {}, {} ...], Bread: [{}, {}, {} ...] I want to use dynamic collection name in my server like // :collection will be "Fruits" or "Bread" app.get('/fetch/:collection', function (req, res){ [req.params.collection].find({}, function(err, docs){ res.json(docs) }) }) But as you know, [req.params.collection].find()... isn't working. How can I use dynamic collection name? 回答1: This is not working as the collection name you are passing is just a

Nodejs mongodb dynamic collection name

好久不见. 提交于 2021-02-09 07:09:22
问题 I have several mongodb collections, Fruits: [ {}, {}, {} ...], Bread: [{}, {}, {} ...] I want to use dynamic collection name in my server like // :collection will be "Fruits" or "Bread" app.get('/fetch/:collection', function (req, res){ [req.params.collection].find({}, function(err, docs){ res.json(docs) }) }) But as you know, [req.params.collection].find()... isn't working. How can I use dynamic collection name? 回答1: This is not working as the collection name you are passing is just a

Nodejs mongodb dynamic collection name

别说谁变了你拦得住时间么 提交于 2021-02-09 07:09:08
问题 I have several mongodb collections, Fruits: [ {}, {}, {} ...], Bread: [{}, {}, {} ...] I want to use dynamic collection name in my server like // :collection will be "Fruits" or "Bread" app.get('/fetch/:collection', function (req, res){ [req.params.collection].find({}, function(err, docs){ res.json(docs) }) }) But as you know, [req.params.collection].find()... isn't working. How can I use dynamic collection name? 回答1: This is not working as the collection name you are passing is just a

How to clone a mongoose document?

夙愿已清 提交于 2021-02-08 17:12:31
问题 This is a followup to Easiest way to copy/clone a mongoose document instance?, which isn't working for me. The following code throws a "cannot edit Mongo _id" field, rather than wiping the ._id and creating a new document in the collection. Is there a better way to clone all values of a document into a new document, for further use/testing/etc? I'm on Mongoose 3.8.12/Express 4.0, and I have also tested this on creating a new ObjectID in the 'undefined' s1._id field below. router.route('/