What do you want to save?
Add Code snippet
New code examples
-
TypeScript 2021-10-29 21:01:11
mongoose typescript global promise
import mongoose from 'mongoose' import consola from 'consola' import q from 'q' export const mongooseConnection = (): void => { mongoose.Promise = q.Promise mongoose.connect(process.env.MONGO_URI, { minPoolSize: 1, maxPoolSize: 20, compressio... Add solution -
Javascript 2021-10-29 06:50:07
auto increment in mongoose + nodejs
... var bookSchema = new Schema({ author: { type: Schema.Types.ObjectId, ref: 'Author' }, title: String, genre: String, publishDate: Date }); bookSchema.plugin(autoIncrement.plugin, 'Book'); var Book = connection.model('Book', bookSchema)... Add solution -
Other 2021-10-28 21:02:14
Mongoose and multiple database in single node.js project
var conn = mongoose.createConnection('mongodb://localhost/testA'); var conn2 = mongoose.createConnection('mongodb://localhost/testB'); // stored in 'testA' database var ModelA = conn.model('Model', new mongoose.Schema({ title : { type : Str... Add solution -
Javascript 2021-10-27 18:53:06
mongoose database pooling
import mongoose from 'mongoose' mongoose.connect(process.env.MONGO_URI, { minPoolSize: 1, maxPoolSize: 20, compression: { compressors: ['zlib'] }, useUnifiedTopology: true, useNewUrlParser: true, useFindAndModify: false, socketTimeoutMS: 6... Add solution -
-
Javascript 2021-10-25 19:36:10
mongoose reference another model
var mongoose = require('mongoose') , Schema = mongoose.Schema var eventSchema = Schema({ title : String, location : String, startDate : Date, endDate : Date }); var personSchema = Schema({ firstname: String, lastname: St... Add solution -
Other 2021-10-24 17:38:11
npm mongoose findorcreate
var findOrCreate = require('mongoose-findorcreate')var ClickSchema = new Schema({ ... });ClickSchema.plugin(findOrCreate);var Click = mongoose.model('Click', ClickSchema); Add solution -
Javascript 2021-10-23 22:14:08
Cast to ObjectId failed for value "t" at path "_id" for model "User"
// it happens when you pass an invalid id to mongoose. // so first check it before proceeding, using mongoose isValid function import mongoose from "mongoose"; // add this inside your route if( !mongoose.Types.ObjectId.isValid(id) ) return fa... Add solution -
Javascript 2021-10-20 19:20:04
mong db connect error
// for mongodb atlas mongoose.connect( "mongodb+srv://<username>:<password>@cluster0.88kbv.mongodb.net/<project_name>?retryWrites=true&w=majority", { useNewUrlParser: true, useUnifiedTopology: true, useCreat... Add solution