Couchbase startkey as literal value - nosql

I am using couchbase to save objects.
The key of a document looks like this
"xxxx_someRandomValue"
For example, i can have this keys
aaaa_1
aaaa_2
aaab_1
aaab_2
I am making a view, which should return me all the documents of which key starts with literal "aaaa".
But, if i specify startKey="aaaa", it also finds for me "aaab", because it is comparing it in unicode values.
Can i force the view to return me just the documents of which key start with literal "aaaa_" ?

Found the solution:
To work as a prefix, this should work
startkey="aaaa"&endkey="aaaa\u02ad"
documentation

Have you tried with an endkey value in addition to your startkey, something like
&startkey="aaaa"&endkey="aaaa\uefff"
You can find more information about sorting here:
http://blog.couchbase.com/understanding-letter-ordering-view-queries

try this one
startkey=aaaa&endkey=aaab

The API startKey(final String KEY) returns all the jsons whose keys (document name) are bigger or equal than the unicode value of KEY.
The API endKey(final String KEY) returns all the jsons whose keys (document name) are smaller than the unicode value of KEY.
So in your case startkey="aaaa"&endkey="aaab" (as suggested by avsej) should give you the desired result.
So the common sense says the API endKey is about compare the end of the key but it's false.

Related

Swift string with key-value, is this format standard ? How can I get it as a dictionary?

I work with an array of string, each string var is a coded object.
I want to decode the object, when I print a string var I get something structured like that :
"firstName=\"Elliot\" lastName=\"Alderson\" gender=\"male\" age=\"33\",some description I also need to get"
Is that a standard format to store key value properties ? I can't find anything on internet. The keys are always the same so that's not a big deal to get theses values as a dictionary but I would like to know if there is like a best practice method to get theses data instead of just searching for each key and then reach value from the first quote to the second one (for each value)
Because my file is 30000 lines so I better choose the more optimized way.
Thanks !

Data factory lookup (dot) in the item() name

I am having lookup wherein salesforce query is there. I am using elements (item()) in subsequent activities. Till now i had item().name or item().email but now i have item().NVMStatsSF__Related_Lead__r.FirstName which has (dot) in the field name.
How should i parse it through body tag so that it reads it correctly?
So I have the following data in item()
{
"NVMStatsSF__Related_Lead__c": "00QE000egrtgrAK",
"NVMStatsSF__Agent__r.Name": "ABC",
"NVMStatsSF__Related_Lead__r.Email": "geggegg#gmail.com",
"NVMStatsSF__Related_Lead__r.FirstName": "ABC",
"NVMStatsSF__Related_Lead__r.OwnerId": "0025434535IIAW"
}
now when i use item().NVMStatsSF__Agent__r.Name it will not parse because of (dot) after NVMStatsSF__Agent__r. And it is giving me the following error.
'item().NVMStatsSF__Related_Lead__r.Email' cannot be evaluated because property 'NVMStatsSF__Related_Lead__r' doesn't exist, available properties are 'NVMStatsSF__Related_Lead__c, NVMStatsSF__Agent__r.Name, NVMStatsSF__Related_Lead__r.Email, NVMStatsSF__Related_Lead__r.FirstName, NVMStatsSF__Related_Lead__r.OwnerId'.",
"failureType": "UserError",
"target": "WebActivityToAddPerson"
this is because ADF uses '.' for object reading.
Could you find a way to rename the field name which contains '.'?
Seems like you need a built-in function to get the value of an object according to the key. Like getValue(item(), 'key.nestkey'). But unfortunately, seems there isn't such a function. You may need handle your key first.
Finally, it worked. I was being silly.
Instead of taking the value from the child table with the help of (dot) operator I just used subquery. Silly see.
And it worked.

How does MongoDB sort/compare objects

Couldn't find any clear documentation on how does MongoDB compare/sort complex objects. I've tried some examples and found out property order does matter and property names also matter
Examples:-
Order matter
{“name”: {“first”: “A”, “last”: “B”}} != {“name”: {“last”: “B”, “first”: “A”}}
Values matter
{“name”: {“first”: “A”}} < {“name”: {“first”: “B”}}
property names matter
{“name”: {“**f**irst”: “A”}} < {“name”: {“**g**irst”: “A”}}
So wondering how exactly does that work, I'm sure stuff like missing properties would also affect this.
If you sort on embedded object fields like name, the sort comparisons are done using at the binary representation (BSON object) level, which isn't very useful.
What you typically want to do instead is identity the specific fields within those objects using dot notation, putting them in the order you want:
// Sort on last name, and then first name
db.test.find().sort({'name.last': 1, 'name.first': 1})

Insert field name with dot in mongo document

A Meteor server code tries to insert an object into a Mongo collection. The value of one of the property is a string which contains a dot i.e. ".".
Meteor terminal is complaining :-
Error: key Food 1.1 and drinks must not contain '.'
What does this mean and how to fix it?
let obj = {
food: group,
rest: rule,
item: item[0],
key: i
};
FoodCol.insert(obj);
edit
The suggested answer by Kishor for replacing the "." with "\uff0E" will produce a space after the dot which is not what a user expects.
From this link, How to use dot in field name?
You can replace dot symbols of your field name to Unicode equivalent
"\uff0E":
Update: As Fred suggested, please use "\u002E" for "."
We solved this issue by encoding (Base64) the key before insertion and decode after taking out from the db. Since we consume the document as it is and query fields are different and their keys are not encoded.
But if u want to make query using this key or the key should be readable to the user, this solution will be not be suitable.

MongoDB: Using *NOT-dot* notation in sort

I'm having an issue with the Mongo sort on nested collection and Google search didn't help:
Dot notation works (returns first element from sorted collection):
db.myCollection.find().sort({ 'comments.Comment' : -1 })[0]
Array (Not-dot) notation doesn't work (always returns first element from un-sorted collection):
db.myCollection.find().sort({ "comments['Comment']" : -1 })[0]
For some business reasons I would like my app to be dynamic and handle spaces/pluses/and few more un-standard characters as the keys in the documents,
So far I was ok with it but sort always returns first (unordered) result if it can't understand the key which I want to sort on.
Simply put:
"For some business reasons I would like my app to be dynamic and handle spaces/pluses/and few more un-standard characters as the keys in the documents"
Yeah, well bad luck it's not valid JSON notation, it may be JavaScript notation but that doesn't mean it's valid JSON. And the BSON spec derives from this fact.
You have dot (.) notation and that is it. So basically your condition is parsed as "invalid" and is ignored, hence no sorting is done how you expect.
Feel free to raise a JIRA issue with MongoDB if you believe this is important.