I have different JSON documents with different properties in a singe CosmosDB container
Student Container
Student Info JSON
{
"id":"00000123",
"rollNum":"1234",
"name":"student 1"
}
Student's Book info JSONs
{
"id":"0000456",
"rollNum":"1234",
"bookName":"Book1",
"bookId":"bk001"
}
{
"id":"0000789",
"rollNum":"1234",
"bookName":"Book2",
"bookId":"bk002"
}
When I query using rollNum:
SELECT c.rollNum, c.bookName, c.bookId FROM c
it gives me this result
{
"rollNum": "1234"
},
{
"rollNum": "1234",
"bookName": "Book1",
"bookId": "bk001"
},
{
"rollNum": "1234",
"bookName": "Book2",
"bookId": "bk002"
}
But what I actually want is
{
"rollNum": "1234",
"books": [
{
"rollNum": "1234",
"bookName": "Book1",
"bookId": "bk001"
},
{
"rollNum": "1234",
"bookName": "Book2",
"bookId": "bk002"
}
]
}
Related
Lets say I have the following JSON structure in my DB:
{
"user": "test",
"cars": [
{
"name": "car1",
"drivers": [
{
"name": "name1",
"age": 18
},
{
"name": "name2",
"age": 21
}
]
},
{
"name": "car2",
"drivers": [
{
"name": "name3",
"age": 25
}
]
}
]
}
I want to remove all the age fields in the nested arrays?
How can I achieve this via MySQL JSON functions?
I have Couchbase documents with structure like this:
{
"subscriberIds": [
{
"type": "END_USER",
"identity": "00000000223"
}
],
"userDataId": "SUB-00000000223",
"status": "ACTIVATED",
"subscriptions": [
{
"id": "Something1",
"attributes": [
{
"value": "Active",
"name": "Status"
}
],
"priority": "1",
"subscriptionStartDate": somedate,
"productShortName": "Something1"
},
{
"id": "Something2",
"attributes": [
{
"value": "Active",
"name": "Status"
}
],
"priority": "1",
"subscriptionStartDate": somedate,
"productShortName": "Something2"
}
],
}
And I'm trying to write a view to get all the 'subscriptions' from all documents in bucket as:
{"total_rows":900,"rows":[
{"id":"Something1","key":null,"value":"00000000223"},
{"id":"Something2","key":null,"value":"00000000223"},
...
but, I can't get nested item from doc
function (doc, meta) {
for (var i in doc.subscriptions) {
emit(doc.subscriptions.id, doc.id);
}
}
I know this is possible, but apparently I do not fully understand the concept of views.
for (var i in doc.subscriptions) {
emit(doc.subscriptions[i].id, doc.id);
}
I am trying to build a bash scripts to manage my google contacts programatically using the google contacts api. From the api-reference I can see the rest api to list full/single contacts entry in xml or json format. But I cannot able see any filter option to fetch name, mobile number alone.
https://www.google.com/m8/feeds/contacts/{userEmail}/full?alt=json
Response:
{
"version": "1.0",
"encoding": "UTF-8",
"entry": {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/xxxxxxxx%40gmail.com/base/xxxxxxxxxxxxxxxx"
},
"updated": {
"$t": "2019-03-16T02:56:27.686Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}
],
"title": {
"$t": "NEW_CONTACT_NAME",
"type": "text"
},
"link": [
{
}
],
"content": {
"$t": "Tets Entry!",
"type": "text"
},
"gd$organization": [
{
"rel": "http://schemas.google.com/g/2005#other",
"gd$orgName": {
"$t": "javis"
}
}
],
"gd$email": [
{
"address": "xxxxxxxxxx#gmail.com",
"rel": "http://schemas.google.com/g/2005#other"
}
],
"gd$phoneNumber": [
{
"label": "Prime",
"uri": "tel:+xx-xxxxx-xxxxx",
"$t": "+xx xxxxx xxxxx"
}
],
"gContact$groupMembershipInfo": [
{
"deleted": "false",
"href": "http://www.google.com/m8/feeds/groups/xxxxxxxx%40gmail.com/base/xxxxxxxxxxxxxxxx"
}
],
"xmlns": "http://www.w3.org/2005/Atom",
"xmlns$batch": "http://schemas.google.com/gdata/batch",
"xmlns$gContact": "http://schemas.google.com/contact/2008",
"xmlns$gd": "http://schemas.google.com/g/2005"
}
}
Could you please help me to find the solution to filter specific field like contact id, name, number or mail from the json response.
For example I have a table of cars, each has a model and a make. A car can only have one of each, and there is a table of models and makes, with their ids auto-generated. Can I reference these in my cars table? What would the JSON look like?
I tried to create a new field in the cars table and specify id in the "Via" text box, but it just creates a new column in the corresponding table, id1. Is there a proper way?
Here is my sample schema JSON:
{
"name": "cars",
"fields": {
"model": {
"object": "models"
},
"make": {
"object": "makes"
}
}
},
{
"name": "models",
"fields": {
"title": {
"type": "string"
},
"make": {
"object": "makes"
},
"id": {
"collection": "cars",
"via": "model"
}
}
},
{
"name": "makes",
"fields": {
"models": {
"collection": "models",
"via": "make"
},
"title": {
"type": "string"
},
"id": {
"collection": "cars",
"via": "make"
}
}
}
In Back& there is no one-to-one relationship by definition but we you have looking for is one-to-many and you almost got it, see the below Model that works.
In the below model a car can have single model and single make (of course a makes and models can have many cars - this is the many part):
{
"name": "cars",
"fields": {
"model": {
"object": "models"
},
"make": {
"object": "makes"
}
}
},
{
"name": "models",
"fields": {
"cars": {
"collection": "cars",
"via": "model"
},
"title": {
"type": "string"
},
"make": {
"object": "makes"
}
}
},
{
"name": "makes",
"fields": {
"cars": {
"collection": "cars",
"via": "make"
},
"models": {
"collection": "models",
"via": "make"
},
"title": {
"type": "string"
}
}
}
I have a JSON document like
{
"branch": [
{
"section": [
{
"sub": "edc",
"time": "one hour",
"frequency": "3"
},
{
"sub": "bee",
"time": "two hours",
"frequency": "4"
}
]
},
{
"section": [
{
"sub": "ss",
"time": "one hour",
"frequency": "2"
},
{
"sub": "ms",
"time": "two hours",
"frequency": "5"
}
]
}
]
}
Now I want to delete
{
"sub": "edc",
"time": "one hour",
"frequency": "3"
}
using "sub":"edc" from the following collection
I want the query to perform changes in mongo db
You need to use $pull, although i've not done it with nested array.
See http://docs.mongodb.org/manual/reference/operator/pull/
Something like: (but you'll need to test it)
db.yourcoll.update( { "branch.section.sub": 'edu' }, { $pull: { "branch.section.sub": 'edu' } } )
This is a similar question:
How to remove an element from a doubly-nested array in a MongoDB document