How to use i18next-node-mongodb-backend? - i18next

Did anyone knows how to store data in mongoDB to be used with https://github.com/gian788/i18next-node-mongodb-backend. Tried couple of things and its not translating keys.
Here is how I am storing my data in mongo
{"en" : { "translation" : { "FirstName" : "First Name", "LastName" : "Lastwq Name" } } }
While printing it always prints key with error
i18next::translator: missingKey en translation FirstName FirstName
Any help?

The format is the following :
{
"_id" : ObjectId("581f3645caa6b31c074dd91c"),
"language" : "en",
"namespace" : "translation",
"data" : {
"FirstName" : "First Name",
"LastName" : "Lastwq Name"
}
}
Obviously you can change the namespace in the init options

Related

Problem requesting additional fields in REST2 api

I am using the RT::Extension::REST2 api (https://metacpan.org/pod/RT::Extension::REST2) for a project and i am having a problem requesting additional fields in some requests.
I need to make a TicketSQL query and for performance reasons i am trying to obtain all the information of a ticket with something like /REST/2.0/ticket/8?fields=Requestor and i get something like
"Requestor": [
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user"
},
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user"
}
]
Notice it is a List of dictionaries, so when i try to do /REST/2.0/ticket/8?fields[Requestor]=Name the field Name does not appear on the dictionaries inside the list.
So i am trying to get something like this:
"Requestor": [
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user",
"Name" : "user20",
},
{
"_url" : "http://<>/REST/2.0/user/example#example.com",
"id" : "example#example.com",
"type" : "user",
"Name" : "user20",
}
]
Is there any way i can do this ?
Thank you for your help!

Create Custom field in Salesforce using Tooling API

I am trying to create custom field using Tooling API in Salesforce. First to check Tooling API, I tried using workbench but it is showing following error:
JSON Parser Error:
message: Cannot deserialize instance of complexvalue from VALUE_STRING value text or request may be missing a required field at [line:5, column:25]
errorCode: JSON_PARSER_ERROR
Following is the JSON body I am using:
{
"DeveloperName" : "CusField",
"Metadata":
{
"type" : "text",
"description" : "test",
"inlineHelpText" : "testhelp",
"label" : "cus Field",
"required" : false,
"precision" : null,
"length" : 255,
"unique" : false,
"externalId" : false,
"trackHistory" : false
},
"TableEnumOrId" : "Account",
"ManageableState" : "installed"
}
Please let me know what is wrong with body?
Thanks in Advance.
There are a few things wrong with the body.
Remove ManageableState
Do not include DeveloperName and TableEnumOrId, instead, use FullName as shown below
Capitalize the field type Text
Here's a working post body:
{
"FullName" : "Account.CusField__c",
"Metadata": {
"type" : "Text",
"description" : "test",
"inlineHelpText" : "testhelp",
"label" : "cus Field",
"required" : false,
"precision" : null,
"length" : 255,
"unique" : false,
"externalId" : false,
"trackHistory" : false
}
}

Scoring documents in Lucene 6.2.0

My query in lucene 6.2.0 goes like:
query query = new PhraseQuery.Builder()
.add(new Term("country","russia"))
.setSlop(1)
.build();
Basically among all my documents which are:
{
"_id" : ObjectId("586b723b4b9a835db416fa26"),
"name" : "test",
"countries" : {
"country" : [
{
"name" : "russia"
},
{
"name" : "USA china"
}
]
}
}
{
"_id" : ObjectId("586b73f24b9a835fefb10ca5"),
"name" : "nitika jain",
"countries" : {
"country" : [
{
"name" : "russia and denmrk"
},
{
"name" : "USA china"
}
]
}
}
{
"_id" : ObjectId("586b744f4b9a835fefb10ca7"),
"name" : "arjun",
"countries" : {
"country" : [
{
"name" : "russia pakistan"
},
{
"name" : "india iraq"
}
]
}
}
I want a document which has only russia. Ideally it should be the one highest scored, but instead I get something like "Found 3 hits."
Document<stored,indexed,tokenized<id:586b723b4b9a835db416fa26> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name:test> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<countries:{ "country" : [ { "name" : "russia"} , { "name" : "USA china"}]}> stored,indexed,tokenized<country:russia> stored,indexed,tokenized<country:USA china>>**0.12874341**
Document<stored,indexed,tokenized<id:586b73f24b9a835fefb10ca5> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name:nitika jain> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<countries:{ "country" : [ { "name" : "russia and denmrk"} , { "name" : "USA china"}]}> stored,indexed,tokenized<country:russia and denmrk> stored,indexed,tokenized<country:USA china>>**0.12874341**
Document<stored,indexed,tokenized<id:586b744f4b9a835fefb10ca7> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<name:arjun> stored,indexed,tokenized,omitNorms,indexOptions=DOCS<countries:{ "country" : [ { "name" : "russia pakistan"} , { "name" : "india iraq"}]}> stored,indexed,tokenized<country:russia pakistan> stored,indexed,tokenized<country:india iraq>>**0.12874341**
All 3 results are equally scored. How can I get the document with only russia to be highest scored?
In Phrase queries, the slop is zero by default, requiring exact matches. that means that if you modify your query in this way:
query query = new PhraseQuery.Builder()
.add(new Term("country","russia"))
.build();
you'll get what you're looking for.

remove specific object from MongoDB collection

I'm trying to remove from MongoDB collection an object (not document) that meets specific value condition, in this case - "Accessible" : "null" - while keeping other instances of this objects. I tried db.collection.update({}, {$unset: { "Accessible":"null"}}, false, true) but it removed all objects with "Accessible" key.Thanks in advance
My MongoDB collection before update
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccc"),
"Name" : "Skyline",
"Accessible" : "Y"
}
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccd"),
"Name" : "Highland",
"Accessible" : "null"
}
Desired result:
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccc"),
"Name" : "Skyline",
"Accessible" : "Y"
}
{
"_id" : ObjectId("52e5f09e8f3d99e1046abccd"),
"Name" : "Highland"
}
You need to first identify the documents you wish to update and then unset that specific field:
db.collection.update(
{"Accessible" : "null"},
{$unset: { "Accessible" : ""}},
{ multi: true }
)
Further documentation on $unset operator:
http://docs.mongodb.org/manual/reference/operator/update/unset/

Errors doing mongodb nested query

I am having a little trouble with nested queries in mongodb.
I have a collection with the following structure --
{
"_id" : Objectid(..),
"result" : {
"name" : nameValue,
"reference" : base64Value,
"city" : cityValue
}
}
Now I am to do two queries in the mongo shell -
search for a specific reference value (so query for equality)
I am using the following query -
db.TestCollection.find("result.reference" : a3d245e343 }
but I get nothing when I know the record is there in the collection
search and print for all city values.
I am looking to print something like this--
{ "city": "new york city" }
{ "city" : "brooklyn" }
... etc
For this I use this query --
db.TestCollection.find( {}, {"results.city", 1} )
For this I do not get the output I was hoping for but only get a list of all "_id" values like this --
{ "_id" : ObjectId("52e466bd562bdb7b1b320d1d") }
{ "_id" : ObjectId("52e466be562bdb7b1b320d1e") }
{ "_id" : ObjectId("52e466be562bdb7b1b320d1f") }
{ "_id" : ObjectId("52e466bf562bdb7b1b320d20") }
{ "_id" : ObjectId("52e466bf562bdb7b1b320d21") }
{ "_id" : ObjectId("52e466bf562bdb7b1b320d22") }
{ "_id" : ObjectId("52e466c0562bdb7b1b320d23") }
{ "_id" : ObjectId("52e466c0562bdb7b1b320d24") }
{ "_id" : ObjectId("52e466c1562bdb7b1b320d25") }
{ "_id" : ObjectId("52e466c1562bdb7b1b320d26") }
{ "_id" : ObjectId("52e466c2562bdb7b1b320d27") }
{ "_id" : ObjectId("52e466c2562bdb7b1b320d28") }
{ "_id" : ObjectId("52e466c2562bdb7b1b320d29") }
{ "_id" : ObjectId("52e466c3562bdb7b1b320d2a") }
{ "_id" : ObjectId("52e466c3562bdb7b1b320d2b") }
{ "_id" : ObjectId("52e466c4562bdb7b1b320d2c") }
{ "_id" : ObjectId("52e466c4562bdb7b1b320d2d") }
{ "_id" : ObjectId("52e466c4562bdb7b1b320d2e") }
{ "_id" : ObjectId("52e466c5562bdb7b1b320d2f") }
{ "_id" : ObjectId("52e466c5562bdb7b1b320d30") }
has more
What am I doing wrong?
I know there are lot of questions regarding queries but I am still wrapping my head around the whole idea. Thanks for helping a newbie out.
I found the issue with both the commands -
For some reason the condition should be given in single quotes like this --
db.TestCollection.find('result.reference' : a3d245e343 }
I thought I can use double quotes in there but looks like I am wrong.
I was using a comma instead of a colon in the projector. The correct answer is -
db.TestCollection.find( {}, {"results.city" : 1} )