MongoDB - SyntaxError: Unexpected token ILLEGAL - mongodb

Am trying to run this simple query and am getting
"SyntaxError: Unexpected token ILLEGAL".
db.Bookdetail.insert({
"Subject":"Book Details",
"Details": [
{
"Book Id":"001",
"Book Name":"C# step by step",
"Book Description":"Programming book on C#"
},
{
"Book Id":"002",
"Book Name":"Head First Java",
"Book Description":"Programming Book on Java"
},
{
"Book Id":"003",
"Book Name":"Steve Jobs",
"Book Description":"biography of Jobs"
}
]
});

It seems that the : in "Book Id":"001" is invalid. Per your code, the :in "Book Id":"001" is full width letter, which is invalid character for JS

please use this code.
db.Bookdetail.insert({
"Subject":"Book Details",
"Details": [
{
"Book Id":"001",
"Book Name":"C# step by step",
"Book Description":"Programming book on C#"
},
{
"Book Id":"002",
"Book Name":"Head First Java",
"Book Description":"Programming Book on Java"
},
{
"Book Id":"003",
"Book Name":"Steve Jobs",
"Book Description":"biography of Jobs"
}
]
});
It seems you copied query form the source, it has invalid character.
Thanks

Related

It is not possible to make nested migrations to Prisma

I'm trying to create my first API on nets.js/prisma/postgresql
But I had difficulties describing the models in the prisma
I want that on request https://my-api/seasons the server gave a response of the form:
[
{
"Season1": {
"name": "Season 1",
"series": {
"seria1": {
"title": "text 1 1",
"url": "url 1 1",
"date": "date 1 1"
},
"seria2": {
"title": "text 1 2",
"url": "url 1 2",
"date": "date 1 2"
}
}
}
},
{
"Season2": {
"name": "Season 2",
"series": {
"seria1": {
"title": "text 2 1",
"url": "url 2 1",
"date": "date 2 1"
},
"seria2": {
"title": "text 2 2",
"url": "url 2 2",
"date": "date 2 2"
}
}
}
}
]
To make it clearer and clearer:
json data example
json data example
This is a simplified kind of migration that doesn't work for me
How can I make the same level of nesting using Prisma migration as I described above?
model Seasons {
id Int #id #default(autoincrement())
name Season #relation(fields: [seasonId], references: [id])
seasonId Int
}
model Season {
id Int #id #default(autoincrement())
name String #db.VarChar(40)
Seasons Seasons[]
}

ItemList error in SDTT: "All values provided for url must point to the same page"

I'm trying to add the ItemList Schema.org markup on an article page that lists top 10 software with (external) links pointing to them.
When I tested the following JSON-LD markup on SDTT, I got the error message saying
All values provided for url must point to the same page
I don't really understand why the individual list items should use the same URL?!
{
"#context": "http://schema.org",
"#type": "ItemList",
"name": "Title of the page",
"description": "Description goes here",
"itemListElement": [
{
"#type": "ListItem",
"position": 1,
"item": {
"name": "Product 1",
"image": "https://www.product-1.com/image",
"URL": "https://www.product-1.com"
}
},
{
"#type": "ListItem",
"position": 2,
"item": {
"name": "Product 2",
"image": "https://www.product-2.com/image",
"URL": "https://www.product-2.com"
}
}
]
}
</script>
I used a slightly different markup without the "item": { as put in https://developers.google.com/search/docs/guides/mark-up-listings, but this time I'm getting an error message that says
All values provided for url must have the same domain
Can you please help me solve this problem?
{
"#context":"https://schema.org",
"#type":"ItemList",
"name": "Title of the page",
"description": "Description goes here",
"itemListElement":[
{
"#type":"ListItem",
"position":1,
"name": "Product 1",
"image": "https://www.product-1.com/image",
"URL": "https://www.product-1.com"
},
{
"#type":"ListItem",
"position":2,
"name": "Product 2",
"image": "https://www.product-2.com/image",
"URL": "https://www.product-2.com"
}
]
}
These errors are about Google’s Carousels feature. This feature requires certain url values:
If used on a summary page, all URLs in the list must point to different pages on the same domain.
If used on an all-in-one-page list, all URLs must point to the page hosting the list structured data.
Your case (linking to external sites) is simply not eligible for getting the Carousels feature in Google Search. You can (and should) keep your JSON-LD like this and ignore these errors in the SDTT.

How to define a REST endpoint for POST requests, expecting single items and lists?

In the API, I'm working on, there is an endpoint, that should be inter alia requested via POST to create a single item like
{
"title": "foo title",
"description": "foo description"
}
but also a list of items like
{
"items": [
{
"title": "foo title",
"description": "foo description"
},
{
"title": "bar title",
"description": "bar description"
},
{
"title": "buz title",
"description": "buz description"
}
]
}
Is it REST-conform, that an endpoint expects (and handles as valid) multiple types of input (a single item and also a list)? Or should only a list be defined as valid input in such a case?
How to meet the requirement and design this endpoint correctly?
I can't see any issues not to do that. In fact, it's up to you to manage the provided content.
Perhaps could you provide a simple array of elements for the list of items:
[
{
"title": "foo title",
"description": "foo description"
},
{
"title": "bar title",
"description": "bar description"
},
{
"title": "buz title",
"description": "buz description"
}
]
I wrote something about this at this url: https://templth.wordpress.com/2015/05/14/implementing-bulk-updates-within-restful-services/. See section "Implementing bulk adds".
Hope it helps you,
Thierry

How to implement TreeTable in sapui5

i have a model like this
[ {"name":"Main 1","description":"main1 Description",
"children": [{
"name": "SUB 1",
"description": "SUB 1 Description",
"children":[
{
"name": "SUB 1.1",
"description": "SUB 1.1 Description"
},
{
"name": "SUB 1.2",
"description": "SUB 1.2 Description"
} ]
}],
"parent":[{"name": "parent sub"}]
},
{"name":"Main 2","description":"main2 Description",children:[],parent:[]},
{"name":"Main 3","description":"main3 Description",children:[],parent:[]},
{"name":"Main 4","description":"main4 Description",children:[],parent:[]}
]
and i want to display name and description property. The contents in the "children" property should be a sub-level in the row, and i don't want to display "parent" content in this tree table. how can i restrict "parent" property from the tree table.
The sap.ui.model.ClientTreeBinding used by the TreeTable with a JSONModel or XMLModel supports the parameter arrayNames.
This parameter expects an array of the model property names that will create a sublevel (if containing an object).
So in your example you should use something like this:
treeTable.bindRows({path: '/pathToData', parameters: { arrayNames: ['children'] }});
or in XMLView:
<TreeTable rows="{path: '/pathToData', parameters: { arrayNames: ['children'] } }" >
...
</TreeTable>
Theres not much to find in the documentation about this except for one example. You can find the source for the example in the openui5 github.
Try This Should Work
var oData={
"children":[
{"name":"Main 1","description":"main1 Description", "children": [], "parent":[]},
{"name":"Main 2","description":"main2 Description","children":[],parent:[]},
{"name":"Main 3","description":"main3 Description","children":[],parent:[]},
{"name":"Main 4","description":"main4 Description","children":[],parent:[]}
]
};
var oTable = new sap.ui.table.TreeTable({
columns: [
new sap.ui.table.Column({label: "Name", template: "name"}),
new sap.ui.table.Column({label: "Description", template: "description"})
],
selectionMode: sap.ui.table.SelectionMode.Single,
enableColumnReordering: true,
expandFirstLevel: true,
});
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
oTable.setModel(oModel);
oTable.bindRows("/children");

How to add an extra field in a sub document in MongoDB?

I've just started working with MongoDB. And I have a document like this:
{
"_id": "12345"
"body": "Here is the body"
"comments":[
{
"name": "Person 1"
"comm": "My comment"},
{
"name": "Person 2"
"comm": "Comment 2"}
]
"author":"Author 1"
}
And I want to change this document to :
{
"_id": "12345"
"body": "Here is the body"
"comments":[
{
"name": "Person 1"
"comm": "My comment"
"checks_": 1
},
{
"name": "Person 2"
"comm": "Comment 2"
"checks_": 4
}
]
"author": "Author 1"
}
I've tried:
db.coll.update({ "_id":12345},{ "$set":{ "comments" :{ "checks_": 1}}})
And this removed all sub documents within comments and added {checks_:1} to it.
Where am I going wrong?
So what you are doing wrong is that the $set operator is doing exactly what it should, and it is replacing only the comments field with the value you have specified. This is not adding an additional document to the array.
You need to be specific and use "dot notation" to "indentify" which array element you are replacing. So to get to your result, you need two updates:
db.coll.update({ "_id":12345},{ "$set":{ "comments.0.checks_" : 1 }})
db.coll.update({ "_id":12345},{ "$set":{ "comments.1.checks_" : 4 }})
That is at least until the next version (as of writing) of MongoDB is released, where you can do bulk updates. And that will not be long now.
A little more geneirc solution (for MongoDb 3.6+):
db.coll.update(
{},
{$set: {"comments.$[element].checks_": 1}},
{multi: false, arrayFilters: [{"element.name": {$eq: "Person 1"}}]}
)
This will add field into specific sub document from the list, matching criteria (name = 'Person 1').
Adding my two cents here.
If you want to add a field to the all the cells, with the same value (in this example: 1 will be added to all of them). You can use the following command:
db.coll.updateMany( {"_id": 12345}, {"$set": {"comments.$[].checks_": 1} }});
And you will get
{
"_id": "12345"
"body": "Here is the body"
"comments":[
{
"name": "Person 1"
"comm": "My comment"
"checks_": 1
},
{
"name": "Person 2"
"comm": "Comment 2"
"checks_": 1
},
...
{
"name": "Person 300"
"comm": "Comment 300"
"checks_": 1
}
]
"author": "Author 1"
}