When storing enum like properties in couchbase, which is the preferred option and why ?
are there any performance considerations ?
how about code maintenance and re-factoring ?
should it be saved as:
{
color : 'red'
}
or
{
color : 1
}
{ color : 'red' } or { color : 1 }
Always do color: red in the database.
Reasons:
When you add a new enum value you don't need to be careful of the 'index'
Self documenting : there is no confusion what red means.
Also. The same should be done in your web API's.
Related
I have a scenario to validate multiple datasets with the same logic. Only change is dataset location.
Eg:
Apple, Sony, MI are the datasets, their data is placed in separate folder. If I pass the variable name as Apple, then in postman body part it should check which data to pass.
Body Section in Postman using JSON
{
"if" : { {{Mobile}} : "Apple"},
"then" : {"location"},
"else":
{
"if" : { {{Mobile}} : "Sony"},
"then" : {"location"}
}
}
If I use the above code, I got the response as Undefined and 200 OK
My expected response should be some ID value (eg: 1,2,3 etc.)
change variable from pre-request, set body as :
{
"mobile":"{{mobile}}"
"location":"{{location}}"
}
and in pre-request
const mobile = pm.variables.get("mobile")
if(mobile ==="Apple"){
pm.variables.set("location","somelocation1")
}else if ( mobile === "sony"){
pm.variables.set("location","somelocation2")
}
I am working with a very large json file, in Atom, I want to know if there is a way to see the json path of where my cursor is at but can't find a package to help me
For example, if my cursor is at Y below, I want something which says
grandparent2:parent:child
I do not wish to collapse all the json to see this.
If Atom cannot help is there another editor which can?
{
"grandparent" : {
"parent" : {
"child" : {
"property" : "X"
}
}
}
"grandparent2" : {
"parent" : {
"child" : {
"property" : "Y"
}
}
}
}
You can refer json editor(https://jsoneditoronline.org/). See the example below and click on node and you will see the path:
https://jsoneditoronline.org/#left=cloud.e461c68e9a9c491781169eeac7b651da&right=local.qefaya
It will look like
can someone please advise how can I convert this JSON body into a REST URI ?
GET api/_search
{
"age":"5",
"aggs" : {
"uniq_gender" : {
"terms" : { "field" : "Gender.keyword" }
}
}
}
You may proceed with one of two options:
Use POST with body
POST api/_search
{
"age":"5",
"aggs" : {
"uniq_gender" : {
"terms" : { "field" : "Gender.keyword" }
}
}
}
It may seem like a hack, but it is simple and frankly it is widely used. Basically from REST perspective it may be considered as resource creation (filter rather than seach might be a better word here).
Use query string with GET.
Something like:
GET api/_search?age=5,field=Gender.keyword
The problem with using query string is that it may be limited. In RFC there is a code for such a case. For example IE browser has such a limit - see details.
Generally speaking if there is no technical problem, readability issue may appear - it is hard to deal with 1000+ symbols string.
Any suggestion would be appreciated.
I have a json file with close to 10000 elements, out of which I need to make a copy of 2000 elements based on a condition and replace an attribute when doing so..
Ex.
Input : jsonData.json
//Other elements
{
"_id" :ObjectId("123"),
"_arryAtt" : {
"attr1":"dummy",
"attr2":"123"
}
}
//Other elements
Output : jsonData.json
//Other elements
{
"_id" :ObjectId("123"),
"_arryAtt" : {
"attr1":"dummy",
"attr2":"123"
}
}
{
"_arryAtt" : {
"attr1":"dummy",
"attr2":"567"
}
}
//Other elements
Id is missing in the copied object..
I am familiar with java
How can I achieve this if I don't' want to write a custom parser...
What kind of scripting can I use to automate this, as running this manually to copy 2000 elements and change one attribute is difficult..
Suppose I have a doc structure like this:
thing: {
name: {
first: "John",
last: "Doe"
}
}
say I want to update the last name only. Which command do I send to update?
$set: {
name: {
first: "Connor"
}
}
or
$set: {
"name.first": "Connor"
}
Is there a difference? Or a preference? I much prefer the first since it resembles the actual document, but mongodb documentation uses the second method.
$set command will take the key and overwrite whatever was stored in it by the value you pass. So in this case
$set: {
name: {
first: "Connor"
}
}
the whole subdocument name with potentially rich structure is getting replaced with a simple {first: 'Connor'}.
Similar thing is happening in the second case, only it is one level deeper. In this case it's a string, but it could be a hash as well.
$set: {
"name.first": "Connor"
}
You can update fields at arbitrary depth level by constructing proper dotted name. Here's a slightly contrived example
db.collection.update(query, {$set: {'stats.daily.20120622.mainpage.visited': 1}});