mongoose

Mongoose populate across 2 databases

瘦欲@ 提交于 2021-02-08 13:58:10
问题 I have a node app that uses 2 databases. One is the the Names and the other for the rest of all the data. I have this connection setup: // DATABASE CONNECTION var APP_DB_URI = config.APP_DB; // mongodb://localhost:27017/app_db var app_DB = mongoose.createConnection(APP_DB_URI); var name_DB = app_DB.useDb(config.NAME_DB); // 'name_db' This connection is working properly. There's also no problem upon saving data to both app_db and names_db working perfect. But the problem is this: when I try to

Ionic 3+ and Node/Express : Http failure response for (unknown url): 0

半世苍凉 提交于 2021-02-08 11:35:54
问题 I've been trying to get data from a local mongodb database, with no success. I've set up a node server using express, cors and mongoose. According to what I've been looking on the internet, this should work : var express = require('express'); var app = express(); var mongoose = require('mongoose'); var cors = require('cors'); app.use(cors({credentials: true, origin: "*", methods: "GET,HEAD,PUT,PATCH,POST,DELETE", preflightContinue:true})); mongoose.connect('mongodb://localhost/cats'); const

Ionic 3+ and Node/Express : Http failure response for (unknown url): 0

放肆的年华 提交于 2021-02-08 11:35:53
问题 I've been trying to get data from a local mongodb database, with no success. I've set up a node server using express, cors and mongoose. According to what I've been looking on the internet, this should work : var express = require('express'); var app = express(); var mongoose = require('mongoose'); var cors = require('cors'); app.use(cors({credentials: true, origin: "*", methods: "GET,HEAD,PUT,PATCH,POST,DELETE", preflightContinue:true})); mongoose.connect('mongodb://localhost/cats'); const

How to provide server-side pagination with NestJS?

血红的双手。 提交于 2021-02-08 11:03:18
问题 Given a MEVN stack using Nestjs, MongoDB(mongoose) I am working to setup server-side pagination. My approach is to use the mongoose-aggregate-paginate-v2, but I have not been able to distill what I need from my research 1 to make this work within the framework of Nestjs(typescript) and mongoose. Thanks for the assist.. Following documentation on Nestjs mongoose models, and mongoose-aggregate-paginate-v2 setup, I have the following: contact.provider.ts import mongoose, { Connection,

mongoose do not return saved document in callback

徘徊边缘 提交于 2021-02-08 09:52:56
问题 I am trying to save a new record using mongoose. I am not getting the saved document in the callback. app.post("/register",(req,res) => { let userData = req.body; let user = new User(userData) user.save().then((err,doc) => { res.json({"success":true,"data":doc}); console.log(doc); }) }); I am getting doc:1. While I should get the whole document. Please help me. "dependencies": { "body-parser": "^1.18.2", "crypto-js": "^3.1.9-1", "express": "^4.15.5", "mongoose": "^4.11.13" } 回答1: You're using

MongoDB aborting when running mongod command on terminal

半世苍凉 提交于 2021-02-08 09:10:38
问题 when i run mongod command on ubuntu terminal i get this error: {"t":{"$date":"2020-10-28T22:27:29.341+05:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"} {"t":{"$date":"2020-10-28T22:27:29.348+05:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"} {"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I", "c":"NETWORK",

Node.js + Mongoose / Mongo & a shortened _id field

这一生的挚爱 提交于 2021-02-08 08:52:29
问题 I'd like the unique _id field in one of my models to be relatively short: 8 letters/numbers, instead of the usual Mongo _id which is much longer. Having a short unique-index like this helps elsewhere in my code, for reasons I'll skip over here. I've successfully created a schema that does the trick (randomString is a function that generates a string of the given length): new Schema('Activities', { '_id': { type: String, unique: true, 'default': function(){ return randomString(8); } }, // ...

Mongoose Compound Index Unique + Sparse

落花浮王杯 提交于 2021-02-08 08:16:44
问题 I want to create an index which ensures, that I don't have a duplicate serialNr within the combination of a manufacturer + art . But some items don't have a serialNr . These I don't want to check/index. Code mySchema.index({ serialNr: 1, art: 1 , manufacturer: 1, deleted: 1}, { unique: true, sparse: true) I tried it also with adding a partial Filter: partialFilterExpression: { serialNr: {$ne:null} } to the index options. Question How can I index it that inserting: [{art: 'a', manufacturer:'a'

How to clone a Mongodb database with Mongoose

泪湿孤枕 提交于 2021-02-08 07:56:34
问题 Is there a way to clone a collection or entire Mongodb database (my databases only have one collection so both options are OK) with Mongoose? I saw that there is a possibility to execute raw Mongo commands with Mongoose. What command can I use to clone an entire collection or db from one db to another? Thanks in advance. 回答1: I had a hard time doing this I don't have any reference. However, this is how I did on my end. 1, I created another collection within the same db: mydb collections:

Mongoose Mixed type field with dates

放肆的年华 提交于 2021-02-08 06:39:40
问题 I'm creating an app where a user can create various types of custom fields, and I'd like to store those fields in mongo. The types will include String, Number, and Date. My schema looks like this: const MetaSchema = new mongoose.Schema({ key: String, value: {type: mongoose.Schema.Types.Mixed}, type: String, created_at: {type: Date, default: Date.now} }); This works great, and I can store my data as expected. The issue is, when I want to store a date for instance, that gets sent across to the