Most voted "mongoose" questions
Mongoose is a Mongodb object modeling tool, or ODM (Object Document Mapper), written in Javascript and designed to work in an asynchronous environment.
Learn more…189 questions
Sort by count of
-
8
votes1
answer221
views -
7
votes1
answer1976
viewsField "__v" in all documents of a collection
All my documents in a Mongodb database have a field __v, what it means? > db.speeds.find({}).limit(2).pretty() { "_id" : ObjectId("586826f700890738a5e8cb3d"), "remoteId" : 1, "first" :…
-
5
votes2
answers2465
viewsWrong time on Mongodb
When I put in the schema mongodb: created: { type: Date, default: Date.now } The time is with a difference of 3 hours more. How can I fix this?
-
5
votes1
answer1150
viewsWhat is the difference between findByIdAndRemove and findByIdAndDelete in Mongoose?
I’m looking for the difference between the two and I can’t find it. They’re synonymous?…
-
4
votes1
answer421
viewsChange field Unique Collection mongodb
Good morning, I have a Collection in the mongodb with a field unique:true. I would like to change this field to false. If I change the code and delete all Collection works, but if I make the change…
-
4
votes3
answers1030
viewsSearch Mongodb Array
I have these two documents in the Mongo: /* 0 */ { "_id" : ObjectId("54f395ef7a5a5ea37af77398"), "HISTORICO" : [], "MOTIVO" : "", "RP_CANCELAMENTO" : "", "DATA_CANCELAMENTO" : null, "RP_FINALIZACAO"…
-
3
votes1
answer488
viewsCreate constants correctly with Mean.js (Node js)
I’m starting to study Mean.js and I was in doubt when the best way to create my application constants. I need to store some constants in the project to be accessible in various parts of the code.…
-
3
votes2
answers896
viewsBlock Save Repeated Data
As I check in the controller, if there is already an email registered in the bank Mongoose and so, lock save it again?
-
3
votes1
answer576
viewsHow to search for the longest date in Mongodb along with other parameters?
I have a schema date, status and code: var entregaSchema = mongoose.Schema({ codEntrega: String, placaPipa: String, codRota: String, codMA: String, dataMA: Date, localMA: String, codPA: String,…
-
3
votes1
answer66
viewsInsert an information into two Collections in Mongodb with Node.js
I have two degrees: courses and participants. an attendee when enrolling in a course, when I give a GET in any course, needs to return the enrolled attendees(participants) and when giving a GET to…
-
3
votes2
answers450
viewsWhat is Aggregate in Mongodb?
I know this kind of doubt I find "easily" in the documentation itself and on the internet, however even in the official documentation became very confused and very technical with several unknown…
-
2
votes1
answer1704
viewsEdit an element within an object, within an array, with Mongoose
I could use a hand! I am new to Node.JS and decided to "create a system" to put into practice what I already know and create challenges to encourage my learning! I did a beginner workshop (with Jean…
-
2
votes2
answers158
viewsError - Password update bcrypt
I am unable to encrypt my password during an update using bcrypt in Mongoose. The password is changed smoothly but without encryption. Follow the schema: var mongoose= require('mongoose');…
-
2
votes1
answer44
viewsGenerate Json x Search in mongodb
I’m generating a Json. But I have the following situation: I have a record of contacts who may belong to the same company. I mean, I can have two people registered in a single company. How do I load…
-
2
votes1
answer329
viewsFind in Bank Mongoose by Nodejs
I’m trying to access the Mongoose bank, doing a find on the nodejs. In Mongoose, I have the following data: Client:{ name: {type: String, trim: true, required: false, default: ""}, address:{…
-
2
votes1
answer645
viewsInserting documents from Mongodb
I have the following document(Schema): var CandidatoSchema = new Schema ({ id_login: Schema.Types.ObjectId, nome: String, cpf: String, dataNascimento: Date, sexo: String, estadoCivil: String,…
-
2
votes1
answer219
viewsModel of the Mongodb
Hello! I’m starting to use Mongodb with Mongoose on Nodejs and I’m finding a strange behavior when creating Models mesus on Mongodb. Example: mongoose.connect('mongodb://localhost/db_teste'); const…
-
2
votes1
answer1163
viewsMongoose - Single object in an array
I’m new to Mongodb and Mongoose, I’d like to ask a question. I would like to store multiple objects in an array, the object being ONLY unique in that array, based on a string. See in the example…
-
2
votes0
answers177
viewsHow to popular a sub list of a document with Mongoose?
Is it possible to popular a list that references another list in the same document? Example in the image below, I want to popular/return in a search always the access link referring to another list…
-
2
votes1
answer900
viewsUsing model.find() with LIKE in Mongoose
I have a function here to do a search on Mongodb using Mongoose, but I would like him to find Brazil when I searched for bra, Bra, Sil, Sil, etc. I looked in the documentation and followed the…
-
2
votes1
answer307
viewsHeroku - Connect with mongoDB addon mLab
I need to connect to the Mongo database using the mLab addon. But I can’t enter or list when I run in local mode it’s working. I have the variable set: Any idea what it might be? My app.js var…
-
2
votes0
answers437
viewsHow to handle errors in Mongoose optimally
I am starting to work with Mongodb + Mongoose and I am having problems dealing with the mistakes that Mongoose generates. One of the same is when there is a duplicate key for a parameter that should…
-
2
votes1
answer113
viewsSearch and replace mongodb database
I have several collections in mongodb and would like to do a "search/replace" for all collections and for each field that is the string "http:" replace with "https:" Example: var object = { "_id" :…
-
2
votes1
answer232
viewsMongodb seeks to return internal arrays
Example of structure: { "_id" : ObjectId("598d4eb912f28534d80a5820"), "nome" : "Emilio", "produtos" : [ { "_id" : ObjectId("598d4fb912f28534d80a5821"), "nome" : "produto1" }, { "_id" :…
-
2
votes1
answer1339
viewsHow to relate two "models" to Mongoosis?
I have two models in my comic book user js. var mongoose = require('mongoose'); var Schema = mongoose.Schema; var bcrypt = require('bcrypt'); // User Model var UserSchema = new Schema({ name: {…
-
2
votes1
answer2626
viewsHow to get a URL parameter in Express?
My URL is coming this way http://localhost:3000/menus/5.5 and it’s bringing all the 5.5 records, but I wish the URL could look like this http://localhost:3000/menus?price=5.5 to have the same…
-
2
votes1
answer69
viewsUpdate on mongoDB is deleting the rest of the document
I have a collection structured like this: { "_id": i43h21n5lk2354, "createdAt" : ISODate("2018-08-19T16:56:31.555Z"), "services" : { "facebook" : { .... name: "Michael Jackson" .... .... } I want to…
-
2
votes1
answer106
viewsAdding multiple IDS within an array?
const [pergunta, setAddPergunta] = useState([]) async function pegarId(_id) {setAddPergunta(_id) console.log(_id)} <tbody> {getPerg.map((pe, i) => ( <tr key={i}> <th…
-
2
votes1
answer101
viewsHow do I make appends on Mongoose models?
I have a model in Mongoose that references another model, and I need to bring the data of this other model in my controller, follow code: Model Empresa.js: 'use strict'; const mongoose =…
-
2
votes3
answers120
viewsProblem with javascript filter in various JSON
I’m trying to capture a certain product for your ID using the filter but there are some problems. It is only returning an empty array. The products are stored within Categories, that is, there is an…
-
2
votes1
answer455
viewsFlutter does not return images from api
I’m trying to get the images from mongodb database, via api I did in nodejs, but it doesn’t work at all, and still presents this error here. Invalid argument(s): No host specified in URI…
-
2
votes1
answer47
viewsHow do I make the user repository use the extends property?
I’m trying to make a generic repository, I’m using Mongodb for that, I tried to import it and use it with the property extends other classes, but did not succeed. What I need is to make the class…
-
2
votes1
answer62
viewsfindByIdAndUpdate() is creating document instead of updating
I am crud using Node, Express and Mongodb, but I have a problem with the update operation when using the findByIdAndUpdate() Mongoose it is not updating the document but creating a new.…
-
1
votes2
answers333
viewsQuery using Mongoose in Nodejs always returns null even within asynchronous method
I am trying to recover a document in my Database using Mongoose in Node.js but it always returns Null. My problem before was the asynchronous method, but now everything is running within it. And I’m…
-
1
votes1
answer366
viewsexport json file
I’m using nodejs, Mongoose. No controllers at the end give a res.json(clientes); and on my route I create: app.get('/clientesjson/:id', isLoggedIn, cliente.clientesjson); I need to access my Json…
-
1
votes0
answers105
viewsMongoose syntax error
I am trying to create an application using express.js and mongodb, when I try to run the server this syntax error appears. The error that appears refers to a zero-only document (Ex: 0000 0000 0000…
-
1
votes1
answer1283
viewsSum of Nodejs + Mongoose values
I need to sum the values stored in a variable in the bank. I have a form and want to know the total value generated in a variable. So I did it this way: _.each(cliente.data, function (data) {…
-
1
votes1
answer112
viewsHelp with the Mongoosis
Not understanding what happened: ready = function() { groups = mongoose.model('groups', schemas.group); groups.find({}, function(err, docs){ for(i in docs){ console.log(docs[i].name); } return docs;…
-
1
votes2
answers250
viewsSum number of records per year and month
I need to generate a Json file that will feed a graph. I need to load the following information. I have a form that receives date(dd/mm/yyyy). My chart shows the number of registered visits per year…
-
1
votes0
answers41
viewsDoubt with Findone in Angularjs using Mongojs error at search time
Hello I am trying to make a search in the bank with this code using the findOne of mongojs, follows code: app.get('/detalhesContato/:id', function(req, res){ var id = req.params.id; console.log(id);…
-
1
votes0
answers96
viewsMean Stack Running the first project
Good afternoon guys, I’m trying to run the Mean stack on my machine (Ubuntu 14.04, 64bits), I followed the step by step site and apparently everything went well when I run the cameo on the ternimal…
-
1
votes0
answers192
viewsHow to model a system of friends with Mongodb?
I’m creating a small social network and I need to create the friendships part. I have two ideas: A Collection Friendships containing the fields sender, destnatary and answer and make a populate with…
-
1
votes0
answers19
viewsMongodb: Find every x days
[Mongodb] Guys, I’m in the following situation: I have several documents saved with the following structure: { ..., repetir : "semanal", a_cada: 2 } In short, I have a cron running daily and I need…
-
1
votes1
answer3114
viewsRelationship in Mongodb
Folks good afternoon, I’m in need of some help from someone who has experience with Mongodb to clear me a doubt. I’m studying about Mongodb and I came across the following problem: I have 2…
-
1
votes1
answer184
viewsCompare multiple arrays
I have two arrays, being them: data [ 0{ nome: a numero: 2 } 1{ nome: b numero: 3 } 2{ nome: b numero: 3 } 3{ nome: b numero: 8 } ] dataNota[ 0{ nf: 9999 numero: 2 } 1{ nf: 2000 numero: 3 } 2{ nf:…
-
1
votes1
answer111
viewsFiltering json data with schema attribute
I have a JSON in this format: { "1": { "cidade":"cidade1", "name":"nome1" }, "2": { "cidade":"cidade2", "name":"nome2" } } and I need to filter the data of this json. For this I made a model.js var…
-
1
votes1
answer516
viewsReuse of connections in Nodejs + Mongoose
I’m starting now with Node and used Mongoose to make my connections to the database in Mongodb. I put 1 log in my application, for every time I open the connection it print in this log. What happens…
-
1
votes1
answer191
viewsHow to get DB value for a variable?
I have the following question: I have a database in mongoDB, I search the data by Nodejs it returns everything right, but I would like to play this value of the search for a variable, to make a…
-
1
votes0
answers139
viewsUse the same Schema inside a daughter key with Mongoose
I’m working with Nodejs, Mongodb and Mongoose where I’m creating a system of access permissions that work with infinite sublevels. Permissions have the same Schema: //app/models/PermissaoModel.js…
-
1
votes1
answer82
viewsHow do you associate a calculus function within an express function to use in Routes?
To with a very big doubt, I have a function that makes calculations of users' metrics and I want to put it in an express function to be able to return a JSON and use it in a route, It follows the…