Creating a REST call with multiple document ID's - rest

I have this URL string:
http://localhost:9033/api/v1/myapi/account/123456/collection/COLL12345
I want to amend it to also include document ID's. There could be one or more documents so I think these should be in some form of array. Should I change my API call from GET to POST and include the document ID's as a JSON array in the message body or is it possible to construct a URL string with them?

You can both add them to the URI path or the URI query. I would use the query for this, something like: /api/v1/myapi/account/123456/collection/COLL12345?ids=[1,4,5]. You need to URI encode the [1,4,5] part and URI decode and JSON parse it on the server.

Related

Check multiple Document exists id Firestore Collection

I want check within a list of 10 document IDs how many exists in a collection. One way to do it would store the document ID inside the document and use in operator.
const result = await this.afs.collection(path).where('id', 'in', ['doc1', 'doc2']).get();
Is there a way we can avoid storing the document id inside document.
For this particular query, you can use FieldPath.documentId(). It returns a token that you can use in the field path of the query:
this.afs.collection(path).where(FieldPath.documentId(), 'in', ['doc1', 'doc2'])
I've linked you to the plain JavaScript documentation. If you're using Angular, it might have a slightly different way of getting this token value, but it will be in a class called FieldPath.

Firestore security rules: check if array contains strings different from user's ID

I know how to check if an array contains a given string (as explained for example here). My requirement however is different: I have a document with an array updatedByHistoryArray written at server side that contains the history of the ids of all users who updated such a document, for example [id1, id2, ..., idn].
I would like to allow a delete operation for this document only if the latter has been updated exclusively by the user who wants to delete it.
So, for example, if a user with id24 wants to delete a document, the updatedByHistoryArray of this document has to be [id24, id24, ..., id24].
Is it possible to implement this requirement in the security rules of Firestore?
It sounds possible. Try using hasOnly() to see if the list field contains only a single user ID.
resource.data.updatedByHistoryArray.hasOnly([request.auth.uid])

Tcl rest interface POST with query

Using the tcllib rest package in interface "mode", how would one POST a key/value pairs while also passing key/value pairs in the query string?
Given one=foo, two=bar for the query string, and three=baz, four=qux for the form submission, how would the config array be structured and how would the call be implemented?

how to insert data on mongo db through restheart api

i am using mongo DB 3.0 version and restheart API 2.0 version. now i am trying to check my queries (URI) through postman chrome interface. and i create a database(test) table(mycol) and two documents in mongo DB, when i filter that data it shows correctly but when i try to insert data into mongodb through postman or HAL Browser it shows error, can you peoples please guide me the syntax format.
Query for filter data, it gives correct result
Query for insert a document, it shows some error
and also i need to know <docid> in the URI format : /<dbname>/<collname>/<docid>[?doc_type=TYPE] what it means <docid> please explain in detail with some example
To create a document you need either to POST the collection POST /test/mycol or PUT a document PUT /test/mycol/<docid>
<docid> stands for document id. the query parameterdocid_type is optional and allows to specify the type of the <docid> in the URL, more information in the documentation Resource URI section.
For instance, if you want to create the following document { "_id": “mydoc", “message”: “hello” } you do
PUT /test/mycol/mydoc { “message”: “hello”}
or
POST /test/mycol { "_id": “mydoc", “message”: “hello” }
In the latter case, if you don’t specify the _id, it will be autogenerated as an ObjectId.
Note that you have to specify the Content-Type request header to be either application/json or application/hal+json.
For instance, using Postman you set the body to be raw and select JSON (application/json) from the dropdown on the right. You'll notice that this will add the Content-Type header to the headers.
I run into the same problem.
The problem was I used field names starting with "_"
i.e. field names like "_type", "_name".
Try to avoid such names.
I had the same problems as you. For insert you should just write your object like this:
{
"code": 20,
"name": "s",
"family": "x"
}
And set POST your method, also for update if the document exists it will be updated, otherwise it will be created.
Please look at this link for more information
https://community.boomi.com/s/article/howtointegratewithmongodbusingopensourcerestheartlibrary#jive_content_id_Scenario_1__InsertUpdate_an_Employee_record_in_Employees_collection_using_POST

Flow Router doesn't work with ObjectID. Any fix?

I'm trying to build routes in my Meteor app. Routing works perfectly fine but getting information from db with route path just doesn't work. I create my page specific routes with this:
FlowRouter.route('/level/:id'...
This route takes me to related template without a problem. Then I want to get some data from database that belong to that page. In my template helpers I get my page's id with this:
var id = FlowRouter.getParam('id');
This gets the ObjectID() but in string format. So I try to find that ObjectID() document in the collection with this:
Levels.findOne({_id: id});
But of course documents doesn't have ObjectIDs in string format (otherwise we wouldn't call it "object"id). Hence, it brings an undefined error. I don't want to deal with creating my own _ids so is there anything I can do about this?
PS: Mongo used to create _ids with plain text. Someting like I would get with _id._str now but all of a sudden, it generates ObjectID(). I don't know why, any ideas?
MongoDB used ObjectIds as _ids by default and Meteor explicitly sets GUID strings by default.
Perhaps you inserted using a meteor shell session in the past and now used a mongo shell/GUI or a meteor mongo prompt to do so, which resulted in ObjectIds being created.
If this happens in a development environment, you could generate the data again.
Otherwise, you could try to generate new _ids for your data using Meteor.uuid().
If you want to use ObjectId as the default for a certain collection, you can specify the idGeneration option to its constructor as 'MONGO'.
If you have the string content of an ObjectId and want to convert it, you can issue
let _id = new Mongo.ObjectID(my23HexCharString);