I am trying to import the following data in a mongodb collection
[
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
]
I am getting errors -
D:\mongodb\bin>mongoimport --db mopi --collection somecountry --type json --file
somecountry.json --jsonArray
connected to: 127.0.0.1
Fri Nov 07 14:20:45.149 exception:BSON representation of supplied JSON array is
too large: code FailedToParse: FailedToParse: Bad characters in value: offset:7
Fri Nov 07 14:20:45.151 [
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
]
Fri Nov 07 14:20:45.152 check 0 0
Fri Nov 07 14:20:45.153 imported 0 objects
Fri Nov 07 14:20:45.153 ERROR: encountered 1 error(s)
I'm assuming that you are showing us an abbreviation of your data. The error says that the BSON resulting from your JSON exceeds the hard 16MB limit. You can fix the problem by reformatting the data. Instead of putting multiple documents in an array and importing with --jsonArray, which restricts the total import size to 16MB, put one json document per line:
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
...
Related
In a log I’d like to match all json objects which type is "sync.out.notify.job.status" and print them. I’m on a Mac (zsh).
I tried: grep -Eo \{.+"sync\.out\.notify\.job\.status".+\}
Mon Jan 11 2021 13:08:46 GMT+0100 (Central European Standard Time) CoreSyncNotifications: sync.out.notify.job.status:
{
"cloudid": "00000000-0000-0000-0000-000000000000",
"job": "files",
"majorstate": "syncing",
"minorstate": "transferring",
"requestid": "45768456-bd58-4cb5-9dff-dfgjfgdj456",
"type": "sync.out.notify.job.status",
"userid": "XXXXXXXXXXXXXXXXXXXXXXXX#AdobeID",
"version": "1.1.43711"
}
Mon Jan 11 2021 13:08:46 GMT+0100 (Central European Standard Time) Vulcan: <- COSY 4.3: sync.out.notify.job.status
Mon Jan 11 2021 13:08:46 GMT+0100 (Central European Standard Time) CoreSyncNotifications: sync.out.notify.job.status:
{
"errors": "",
"cloudid": "00000000-0000-0000-0000-000000000000",
"job": "files",
"majorstate": "idle",
"minorstate": "complete",
"requestid": "4856658fdgh-efb3-4da9-b5f5-4856658fgj",
"type": "sync.out.notify.job.status",
"userid": "XXXXXXXXXXXXXXXXXXXXXXXX#AdobeID",
"version": "1.1.43711"
}
Mon Jan 11 2021 13:08:46 GMT+0100 (Central European Standard Time) WebSocketServer: client_7: SEND syncstate creative_cloud: ok
grep usually searches pattern in single line only unless you use -z option in gnu grep.
You may try this gnu awk command:
awk -v RS='(^|\n){[^}]+?sync.out.notify.job.status[^}]+}(\n|$)' 'RT {printf "%s", RT}' file
{
"cloudid": "00000000-0000-0000-0000-000000000000",
"job": "files",
"majorstate": "syncing",
"minorstate": "transferring",
"requestid": "45768456-bd58-4cb5-9dff-dfgjfgdj456",
"type": "sync.out.notify.job.status",
"userid": "XXXXXXXXXXXXXXXXXXXXXXXX#AdobeID",
"version": "1.1.43711"
}
{
"errors": "",
"cloudid": "00000000-0000-0000-0000-000000000000",
"job": "files",
"majorstate": "idle",
"minorstate": "complete",
"requestid": "4856658fdgh-efb3-4da9-b5f5-4856658fgj",
"type": "sync.out.notify.job.status",
"userid": "XXXXXXXXXXXXXXXXXXXXXXXX#AdobeID",
"version": "1.1.43711"
}
You can easily and robustly use a JSON-aware tool like jq for this, assuming you want to print the matching blocks:
$ grep -v '^[[:alpha:]]' file | jq 'select(.type=="sync.out.notify.job.status")'
{
"cloudid": "00000000-0000-0000-0000-000000000000",
"job": "files",
"majorstate": "syncing",
"minorstate": "transferring",
"requestid": "45768456-bd58-4cb5-9dff-dfgjfgdj456",
"type": "sync.out.notify.job.status",
"userid": "XXXXXXXXXXXXXXXXXXXXXXXX#AdobeID",
"version": "1.1.43711"
}
{
"errors": "",
"cloudid": "00000000-0000-0000-0000-000000000000",
"job": "files",
"majorstate": "idle",
"minorstate": "complete",
"requestid": "4856658fdgh-efb3-4da9-b5f5-4856658fgj",
"type": "sync.out.notify.job.status",
"userid": "XXXXXXXXXXXXXXXXXXXXXXXX#AdobeID",
"version": "1.1.43711"
}
Here's another way to get from { to } to pipe to jq:
$ sed -n '/^{/,/^}/p' file
{
"cloudid": "00000000-0000-0000-0000-000000000000",
"job": "files",
"majorstate": "syncing",
"minorstate": "transferring",
"requestid": "45768456-bd58-4cb5-9dff-dfgjfgdj456",
"type": "sync.out.notify.job.status",
"userid": "XXXXXXXXXXXXXXXXXXXXXXXX#AdobeID",
"version": "1.1.43711"
}
{
"errors": "",
"cloudid": "00000000-0000-0000-0000-000000000000",
"job": "files",
"majorstate": "idle",
"minorstate": "complete",
"requestid": "4856658fdgh-efb3-4da9-b5f5-4856658fgj",
"type": "sync.out.notify.job.status",
"userid": "XXXXXXXXXXXXXXXXXXXXXXXX#AdobeID",
"version": "1.1.43711"
}
I normally wouldn't suggest using a range expression over using a flag but in this case since it's ALL you're going to do with it, it's probably fine.
I have a JSON object which has 100000 records. I want a select a record which has specific value to the one of the key
Eg:
[{
"name": "bindu",
"age": "24",
"qualification": "b.tech"
},
{
"name": "naveen",
"age": "23",
"qualification": "b.tech"
},
{
"name": "parvathi",
"age": "23",
"qualification": "m.tech"
},
{
"name": "bindu s",
"status": "married"
},
{
"name": "naveen k",
"status": "unmarried"
}]
now I want to combine the records which are having the name with 'bindu' and 'bindu s. We can achieve this by iterating on the JSON object but since the size is more it is taking more time. Is there any way to make this easy.
I want the output like
[{
"name": "bindu",
"age": "24",
"qualification": "b.tech",
"status": "married"
},
{
"name": "naveen",
"age": "23",
"qualification": "b.tech",
"status": "unmarried"
},
{
"name": "parvathi",
"age": "23",
"qualification": "m.tech"
"status": ""
},
This will rename and merge your objects by first name.
jq 'map(.name |= split(" ")[0]) | group_by(.name) | map(add)'
I tried to populate mat-select options from JSON file, but appears a error like
SyntaxError: Unexpected token n in JSON at position 8584 at JSON.parse () at XMLHttpRequest.onLoad
I created a service to get list:
getCountries(): Observable<ICountry[]>{
return this.http.get<ICountry[]>(this._url);
}
Here I tried to populate the array:
this._countriesService.getCountries()
.subscribe(data => this.countries = data,
error => console.log(error));
and the html code looks like:
<mat-form-field>
<mat-label>Country From</mat-label>
<mat-select>
<mat-option>None</mat-option>
<mat-option *ngFor="let country of countries" [value]="country.name">{{country.name}}</mat-option>
</mat-select>
</mat-form-field>
JSON file:
[
{"name": "Afghanistan", "code": "AF"},
{"name": "Åland Islands", "code": "AX"},
{"name": "Albania", "code": "AL"},
{"name": "Algeria", "code": "DZ"},
{"name": "American Samoa", "code": "AS"},
{"name": "AndorrA", "code": "AD"},
{"name": "Angola", "code": "AO"},
{"name": "Anguilla", "code": "AI"},
{"name": "Antarctica", "code": "AQ"},
{"name": "Antigua and Barbuda", "code": "AG"},
{"name": "Argentina", "code": "AR"},
{"name": "Armenia", "code": "AM"},
{"name": "Aruba", "code": "AW"},
{"name": "Australia", "code": "AU"},
{"name": "Austria", "code": "AT"},
{"name": "Azerbaijan", "code": "AZ"}
]
And I need to show all names to mat-select.
Thank you.
I want to find and delete 'indicent' object in my json using sublime. here's the regex
\s*+,\s*(.)+"\s*indices+"\s*:\s*+(.)\s*\s*(.)+\s*(.)+\s*+]
but, it's ran out of stack space. i think that regex isn't effiecient.
json example :
"created": "Fri Nov 27 11:12:43 +0000 2015",
"text": "https://t.co/8r5dQ7zRYG #johnl3375 Kim Gi Jung",
"source": "NOMOR1",
"hashtags": [
{
"text": "johnl3375",
"indices": [
24,
34
]
}
],
"url": [
{
"url": "https://t.co/8r5dQ7zRYG",
"expanded_url": "https://play.google.com/store/apps/details?id=com.aturkeuangan.nomor1#refid=johnl3375",
"display_url": "play.google.com/store/apps/det…",
"indices": [
0,
23
]
}
]
i want json like this
"created": "Fri Nov 27 11:12:43 +0000 2015",
"text": "https://t.co/8r5dQ7zRYG #johnl3375 Kim Gi Jung",
"source": "NOMOR1",
"hashtags": [
{
"text": "johnl3375"
}
],
"url": [
{
"url": "https://t.co/8r5dQ7zRYG",
"expanded_url": "https://play.google.com/store/apps/details?id=com.aturkeuangan.nomor1#refid=johnl3375",
"display_url": "play.google.com/store/apps/det…"
}
]
what should my regex be?
This works for me in ST3 using your JSON example: [\s,]+"indices":[^]]+]
I am trying to populate listview from JSON data but its not working -
the Json
{
"reg": {
"user": [{
"LastEdited": "16 Apr 2014 03:18:25",
"Picture": "\/storage\/sdcard0\/XLEZData\/XLEZ_Input\/Client\/22U2621210__PIN_Ver1.0\/image002.png",
"Email": "adil#adil.com",
"Name": "adil"
}, {
"LastEdited": "16 Apr 2014 03:18:55",
"Picture": "\/storage\/sdcard0\/XLEZData\/XLEZ_Input\/Client\/22U2621210__PIN_Ver1.0\/image002.png",
"Email": "adil",
"Name": ""
}, {
"LastEdited": "24 Apr 2014 10:57:34",
"Picture": "\/storage\/sdcard0\/Pictures\/Screenshots\/Screenshot_2013-07-11-14-33-35.png",
"Email": "test#s3.com",
"Name": "s3 test"
}]
}
}
I have this list in native android like this
How can i make this in jQueryMobile ?