Categories
Mastering Development

Making a post/put request to an object inside an array

I have many documents like the following stored inside mongo DB. { “posts”: [ { “_id”: “5ee38b041385d900004e78de”, “postName”: “Driver one”, “hasSublevels”: false, “isChildOfOther”: false, regions: [] }, { “_id”: “5ee38b0e1385d900004e78df”, “postName”: “Driver 2”, “hasSublevels”: true, “isChildOfOther”: false, regions: [] }, { “_id”: “5ee38b1b1385d900004e78e0”, “postName”: “Driver 3”, “hasSublevels”: true, “isChildOfOther”: true, regions: [] }, { “_id”: […]

Categories
Mastering Development

I get an error when trying to establish a $ lookup relationship in Mongodb and nodejs

I’m at the learning stage yet. I am having trouble establishing a relationship in Mongodb. error not found 404 I made all the operations in the collections with the data in both tables, and in the training I received. But somehow I couldn’t run it successfully. Models Books const Book = require(‘../Models/Book’); router.post(‘/new’, function(req, res, […]

Categories
Mastering Development

NodeJS – Nested Promise inside a for loop

I am trying to do a call which retrieves a list of categories. Inside this call I want to loop through the categories and retrieve the items for each category and return them all together. My call retrieves the categories perfectly before I added the loop to retrieve the items. To double check my call […]

Categories
Mastering Development

Keep track of last login date with NodeJS and MongoDB

I’m working on adding a last login functionality to my Node app and can’t seem to get it to work. Here’s what I’ve got for a mongoose user schema: userSchema = new mongoose.Schema({ username: { type: String, unique: true }, password: String, email: { type: String, unique: true }, avatar: String, firstName: String, lastName: String, […]

Categories
Mastering Development

How to populate inside array of array

I want to access id’s inside the recordId [ { recordId: [ 5d836ceb2afc1764751f8d8c, 5d836ceb2afc1764751f8d92, 5d836ceb2afc1764751f8d95 ], isDelete: false, _id: 5ec278f6da31482240554476, createdAt: 2020-05-18T12:00:54.355Z, updatedAt: 2020-05-18T12:00:54.355Z, __v: 0 }, { recordId: [ 5d836ceb2afc1764751f8d8c, 5d836ceb2afc1764751f8d92, 5d836ceb2afc1764751f8d95 ], isDelete: false, _id: 5ec276334e094223c84a398e, createdAt: 2020-05-18T11:49:07.691Z, updatedAt: 2020-05-18T11:49:07.691Z, __v: 0 }, … ]

Categories
Mastering Development

mongoose find and return res.status.json

I’m developing an API that shows the bulletin boards list. And it also shows one of the latest posts at the same time. In controller I coded like this exports.boards_get_all = (req, res, next)=>{ Board.find() .exec() .then(boards=>{ res.status(200).json({ count: boards.length, boards: boards.map(board=>{ return { board: { id:board._id, name: board.name, order: board.order }, post : Post.findOne({boardId:board._id}) […]

Categories
Mastering Development

Push objects from MongoDB to an array located in React Hook

I’m struggling to understand the logic behind adding an object to an array defined within a React hook. I am getting an object from my database which returns a JSON, which you can see at the bottom of this post. I am trying to access that data using axios, which is connected to my backend […]

Categories
Mastering Development

Duplicate mongodb objects params but only one gets shown? Last digits get rounded?

So I am experiencing a number of oddities with my db. It started when I noticed after I logged in that my balance was not what it used to be. Then I found two apparently different accounts that have the same number. Anyways. I am working with passport and the strategy is steam. Here is […]

Categories
Mastering Development

Search and lookup arrays nested in multiple objects

I find all websites that match the IDs I have in my array and in the below case it is two websites. I then want to look inside each of the conversations arrays of those websites and search a different collection called conversations for conversations that match those IDs. I then want to grab some/all […]

Categories
Mastering Development

I want to add the array values to the csv file from mongodb using nodejs

I have the following sample data, [ { “_id”: “5e88624da92cf342ac9357a3”, “defaultAccountId”: 1009, “grnNo”: “17 – 20/21”, “party”: “Adash”, “buyer”: “Amurtha Knit Lab”, “lotNo”: “1005”, “orderNo”: “5005”, “dyeingDcNo”: “52003”, “dyeingDcDate”: “2020-03-04T05:09:05.584Z”, “dyeingName”: “sathya”, “partyDcNo”: “1005”, “partyDcRolls”: 454545, “partyDcDate”: “2020-03-04T05:09:05.584Z”, “weight”: 25.366, “reference”: “naveen”, “operationDisplay”: [ { “operationStatus”: “Completed”, “completedAt”: “2020-04-04T10:32:45.705Z”, “processName”: “Heating”, “lab”: “amurtha”, “machine”: “high […]