Prob- I want to query saved data from datastore as
id - [1,2,3]
2ndid - something,
Solution- It must get all the records for id-[1,2,3] where 2ndid - something gets match,
basically I want to filter based on 2ndId-something and want to get all records for the item which gets matched from id array.
ex- Table
id 2ndid
1 something
2 something
after query i must get records of id[1,2] as id[3] is not present
I tried for single id and single 2nd id, it worked but not working for array.
Related
I have a scraped some sports data, which contains an id field that ideally I'd like to use as Mongo's "_id". It's event based data and the IDs are meant to be unique however there is a few cases where they are not. However each entry also has a match id value, which is unique. There is never duplicated event IDs for the same match id. I was looking for a way to concatenate the two fields to create a unique id value that I could then use as the "_id" but this doesn't seem possible. I tried using the $concat operation with $tostring however this results in values such as 54821.4e+09
For example, a document with match id 3181621 and event id 1339018347 using
{$project:{"new_id":{$concat:[{"$toString":"$matchId"},"",{"$toString":"$id"}]}}}
results in "new_id" : "3181621.33902e+09", when I would want it to be 31816211339018347
I'm using this php package to make queries - https://github.com/jenssegers/laravel-mongodb
The situation is, there are two fields, user_id and post_status among others. I want to retrieve all the documents in that collection, but when post_status field value is draft, that should be retrieved only when user_id is a given string. The idea is, only logged in user finds their drafted posts among other posts.
I'm having hard time finding any solution for this problem. The app is still not in production. If I should store data is some different manner, that is an option as well.
Find documents with a certain field value only when another field value is a given string
The question your are framing is simply convert into a and query, how let's see it
when another field value is a given string
This means that you have some result sets and you need to filter out when user_id match with some string. i.e some result sets and user_id = <id>
Now consider the first part of the sentence Find documents with a certain field value
This means you are filtering the records with some values i.e "status" = "draft" and whatever result will come and want again to filter on the basis of user_id = <id>
So finally you will end-up with below query:
db.collectionName.find({"status":"draft", "user_id": "5c618615903aaa496d129d90"})
Hope this explanation will help you out or you can rephrase your question I will try to modify by ans.
Are lokijs id's ($loki) unique?
if I have 2 documents from one collection with $loki:1 and $loki:2 as id's, and I delete $loki:1, the next one I create should it be $loki:3 ???
That's correct. Collections keep track of the last ID that was created and assign the a lastId + 1 value to the $loki property of the next object you insert in a collection. You can check the value of the last id by checking collection.maxId and deduce the next id by simply adding 1 to that.
I have problem whit long Mongo find results. Example how can i start query starting from _id X
to forward Example I know I have document where is 1000 users details I know there is user called Peter in list I can make query Users.find({userName: "Peter"}) and get this on user _id but how I can get all users also after this with out I need return JSON from above "Peter"
With the little amount of information you have given, You need to do this in two steps:
Get the id of the first record that matches the name "peter".
db.test.findOne({"userName":"Peter"},{"_id":1});
Returns one document that satisfies the specified query criteria. If
multiple documents satisfy the query, this method returns the first
document according to the natural order which reflects the order of
documents on the disk. In capped collections, natural order is the
same as insertion order.
Once you have the id of the record with peter, you can retrieve the records with their id > the id of this record.
db.test.find({"_id":{$gte:x}});
Where, x is the id of the first record returned by the first query.
I have one json array of Objects.I am creating sphinx compatible xml document from this JSON Array.For each object i create one document and specify id value for it.For example if json array contains 20 objects then i have to create 20 documents starting from 1 to 20.Now my json array update with time and new Objects come in place so i need to assign them id starting from 21 and so on.So is there any way to maintain this id values from Sphinx side internally?
Just store the latest used id somewhere. A text file or something.
Or just get the highest id from the sphinx index. So the script building the xml file, could just first run a sphinxql query
select id from gi_stemmed order by id desc limit 1;