Get all items on strapi collection - node.js

I am using Strapi API on my project, and I would like export my data in CSV file format.
For this, I use a find() request, but the API returns only the first 100 items and I've ~ 2000 items in my database.
Is it possible to remove the limit on my Strapi request ?

For that, you will have to use the _limit filter and use -1 as value.
eg. strapi.query('restaurant).find({_limit: -1});
After that I suggest you export directly from your database it will be easier.

Related

How can I select specific fields using the firestore modular api

In the <= V8 Firestore API I could query a set of documents and extract a subset of fields with code like the following:
const membersRef = db.collection('members');
const snapshot = await membersRef.select('First', 'Last').get();
With the new modular api I can do the following:
import { collection } from 'firebase/firestore';
const membersRef = collection(db,'members');
// how to select only First and Last from members ?
I can't find a select() function to specify fields in the new api. How can this be done using the V9 modular api?
I know I can read the entire collection and use .map()/.forEach to reduce the fields but I have some large fields I would rather not query unless I need them for a specific document. The use of select to have the server pull out only the fields needed is useful.
The client-side SDKs for Firebase don't have a select method/function, but always retrieve full documents. So the select method didn't exist in the v8 CollectionReference or Query classes, nor does it exist as a top-level function in the v9 modular SDK.
There is a select() method in the Admin SDK for Node.js, but that one still works as a method on CollectionRefence as far as I can tell.

Changing collection name according to query parameters in Nestjs

Can we get data from different collections of same or multiple mongo databases according to the query parameters in nest js ?
For example if parameter says get data from collection A, then collection A data should be displayed if it says get data from collection B, then collection B data should be displayed.
Can we do it in same controller or we need to make multiple controllers ?
I got it, I just have to make two models from different collections and use the desired model according to query parameter by using simple if then else.

Choose data from mongoDB in browser and display results

I am new to NodeJS, MongoDB and express.
I am able to insert, delete and update data but I dont really know how to work with it.
I want to choose some data(e.g. from a dropdown form) and then pass that data to some functions and calculate results. How is it possible to show the results to the client in the webpage(e.g. in a table)?
For example: I have different JSON objects stored in my database and now I want to select one by the name. Then do some calculations with it and show the results to the client.
Also: Is it possible to tell the Database to only accept valid JSON data?
Yes you can get specified data from the database and it will work a lot better with mongoose. You can define schema in mongoose and you can focus more on the data instead of how your data look like. And you can do validation to accept the valid data.

How to get data from elastic search, if new data came then update it, and again inject it?

I have nearly 200 000 lines of tuples in my Pandas Dataframe. I injected that data into elastic search. Now, when I run the program It should check whether the present data already there in elastic search if not present insert into it.
I'd recommend to not worry about it and just load everything into Elasticsearch. As long as your _ids are consistent the existing documents will be overwritten instead of duplicated. So just be sure to specify an _id for each document and you are fine, the bulk helpers in the elasticsearch-py client all support you setting an _id value for each document alredy.

Mongoose bulk insert or update documents

I am working on a node.js app, and I've been searching for a way around using the Model.save() function because I will want to save many documents at the same time, so it would be a waste of network and processing doing it one by one.
I found a way to bulk insert. However, my model has two properties that makes them unique, an ID and a HASH (I am getting this info from an API, so I believe I need these two informations to make a document unique), so, I wanted that if I get an already existing object it would be updated instead of inserted into the schema.
Is there any way to do that? I was reading something about making concurrent calls to save the objects, using Q, however I still think this would generate an unwanted load on the Mongo server, wouldn't it? Does Mongo or Mongoose have a method to bulk insert or update like it does with insert?
Thanks in advance
I think you are looking for the Bulk.find(<query>).upsert().update(<update>) function.
You can use it this way:
bulk = db.yourCollection.initializeUnorderedBulkOp();
for (<your for statement>) {
bulk.find({ID: <your id>, HASH: <your hash>}).upsert().update({<your update fields>});
}
bulk.execute(<your callback>)
For each document, it will look for a document matching the {ID: <your id>, HASH: {your hash}} criteria. Then:
If it finds one, it will update that document using {<your update fields>}
Otherwise, it will create a new document
As you need, it will not make a connection to the mongo server on each iteration of the for loop. Instead a single call will be made on the bulk.execute() line.

Resources