Update objects from an array in a MongoDB collection - javascript

I need to send an array of objects with respective ID's from client-side code via JSON to an API endpoint that is serve by ExpressJS.
Now I need to update existing DB objects with all the fields from the array of objects. I suppose a for..in loop doesn't look good in this case. Neither did I find a way to update multiple documents in one run.
I use MongoJS library to work with MongoDB from NodeJS
Please advise.

may be
db.mycollection.update({name:'some name'}, {$inc:{level:1}}, {multi:true}, function() {
// the update is complete
});
for mongojs library help you...
Thanks

Related

Why mongoose.model() is required to get data from MongoDB?

I want to read data from the mongodb with mongoose, but every time it requires creating a model. Why?
I thought model are just like templates to insert data to MongoDB.
Can anyone describe what exactly mongoose.model() is and how it works?
I tried
const Model = mongoose.model(mongoose.Schima())
Without object in it
And it worked as well!!!
How does mongoose.model get data in background?
Thank you...
Mongoose models are much more than just templates on how to store data in the database: they perform type conversion, provide validation, have pre/post hooks, provide easy methods for population, and much more.
You don't need to use a full model to retrieve data from the database (in fact, you don't even need Mongoose at all), but you'll lose all the additional features.

How to push a js object to a json array using postgreSQL?

Im using supabase. i have a json array column in a table. it is a little difficult to push an object to it. i should get that json array, push an object to it and update that column. i should send two requests and its not what i want because it makes some problem in my web app.
I was looking for answer and i found postgreSQL. I can create my custom query and i can for example write a query that takes an object and push that to a column. And thankfully i can use it in supabase. But i have a lot of problem in using this. Can you please tell me how can i write a query that gets an object and push that object to a column in supabase?
I tested some queries. I found some json methodes in postgreSQL document and i tested them but i got error. Thanks for helping

Firebase database retrieving data from comma seperated list

I want to store the comma separated ids on a child node & how can I filter data as in sql we can use IN clause to fetch data any possibility in firebase to perform this kind of operation in firebase database.
Please suggest any possible solution for this.
Firebase Realtime Database doesn't have the equivalent of SQLs IN clause. It also doesn't have a way to find a substring in a value. So the data model you are looking to use, doesn't allow the use-case you want. As usual with NoSQL databases, the solution is to pick a data model that does allow your use-case..
The most likely cause I know for the structure you describe is to associate the child node with a bunch of categories. If that is your case, read my answer here for a proper data structure: Firebase query if child of child contains a value
This is one of the cases where the new Cloud Firestore database offers better querying support, since it recently added a feature to efficiently test if an array contains a certain value (video). If you're only just getting started with your project, you might want to check if Firestore is a better fit for your use-cases.

Database using JSON Jquery

I am new to Jquery JSON. I wanted to know is it possible to use JSON as a database to store data and retrieve data whenever it is needed. Like instead of using mysql,or mssql or anything else is there any way to use only JSON(i.e. .json file)??
If yes can you please guide me? if no can anybody suggest a better way to store data?
And i need to know this for asp.net webforms.
You could use MongoDB instead of MySQL. MongoDB is based on "JSON" document storage. Example of CRUD with Mongo: insert and find data.
db.inventory.insert({
item: "ABC1",
details: {
model: "14Q3",
manufacturer: "XYZ Company"
}
})
db.inventory.find( { item: "ABC1" } )
From mongodb.com
The MongoDB BSON implementation is lightweight, fast and highly
traversable. Like JSON, MongoDB's BSON implementation supports
embedding objects and arrays within other objects and arrays – MongoDB
can even "reach inside" BSON objects to build indexes and match
objects against query expressions on both top-level and nested BSON
keys. This means that MongoDB gives users the ease of use and
flexibility of JSON documents together with the speed and richness of
a lightweight binary format. Read our MongoDB overview to learn more
about these features.
There is also a similar question on SO here
It is definitely possible and it depends, if it suits your requirement then go ahead and use mongodb. To have json as your datastore I would recommend to use MongoDB one of the popular NOSQL(Not only SQL) DB.
But if your data has lots of relation between different entities then it's not recommended to use MongoDB.
Go through this article, it gives you detailed explanation when to and when not to use NoSQL DB
http://www.sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/

Meteor JS database workflow

As far as I understand, I "publish" named collection server-side, on the client side I "subscribe" to that collection and pass them to Template, where I work only with the data, provided by "published" collection.
Please comment, have I got it right, and what should I do if I have a big collection that I don't want to retreive at once?
That is correct. When using large collections you should add parameters to the publish and/or limit the amount of records being published.
Theres a good explanation about publish/subscribe on Meteorpedia

Categories