In this part, we will gain proficiency with the various tasks with Arangosh.
Coming up next are the potential tasks with Arangosh −
- Making a Document Collection
- Making Documents
- Understanding Documents
- Refreshing Documents
Allow us to begin by making another data set. We will utilize the accompanying line of code to make another data set −
127.0.0.1:8529@_system> db._createDatabase("song_collection")
true
The accompanying line of code will help you move to the new information base −
127.0.0.1:8529@_system> db._useDatabase("song_collection")
true
Brief will move to "@@song_collection"
127.0.0.1:8529@song_collection>
From here we will consider CRUD Operations. Allow us to make an assortment into the new information base −
127.0.0.1:8529@song_collection> db._createDocumentCollection('songs')
Yield
[ArangoCollection 4890, "songs" (type document, status loaded)]
127.0.0.1:8529@song_collection>
Allow us to add a couple of reports (JSON objects) to our 'tunes' assortment.
We add the main report in the accompanying manner −
127.0.0.1:8529@song_collection> db.songs.save({title: "A Man's Best Friend",
lyricist: "Johnny Mercer", composer: "Johnny Mercer", Year: 1950, _key:
"A_Man"})
Allow us to add different records to the data set. This will assist us with learning the way toward questioning the information. You can duplicate these codes and glue the equivalent in Arangosh to imitate the cycle −
127.0.0.1:8529@song_collection> db.songs.save(
{
title: "Accentchuate The Politics",
lyricist: "Johnny Mercer",
composer: "Harold Arlen", Year: 1944,
_key: "Accentchuate_The"
}
)
{
"_id" : "songs/Accentchuate_The",
"_key" : "Accentchuate_The",
"_rev" : "_VjVDnzO---"
}
127.0.0.1:8529@song_collection> db.songs.save(
{
title: "Affable Balding Me",
lyricist: "Johnny Mercer",
composer: "Robert Emmett Dolan",
Year: 1950,
_key: "Affable_Balding"
}
)
{
"_id" : "songs/Affable_Balding",
"_key" : "Affable_Balding",
"_rev" : "_VjVEFMm---"
}
Step by step instructions to Read Documents
The _key or the report handle can be utilized to recover an archive. Use record handle if there is no compelling reason to cross the actual assortment. In the event that you have an assortment, the record work is not difficult to utilize −
127.0.0.1:8529@song_collection> db.songs.document("A_Man");
{
"_key" : "A_Man",
"_id" : "songs/A_Man",
"_rev" : "_VjVClbW---",
"title" : "A Man's Best Friend",
"lyricist" : "Johnny Mercer",
"composer" : "Johnny Mercer",
"Year" : 1950
}
Step by step instructions to Update Documents
Two choices are accessible to refresh the saved information − supplant and update.
The update work fixes an archive, combining it with the given ascribes. Then again, the supplant capacity will supplant the past record with another one. The substitution will in any case happen regardless of whether totally various ascribes are given. We will initially notice a non-dangerous update, refreshing the quality Production' in a tune −
127.0.0.1:8529@song_collection> db.songs.update("songs/A_Man",{production:
"Top Banana"});
Yield
{
"_id" : "songs/A_Man",
"_key" : "A_Man",
"_rev" : "_VjVOcqe---",
"_oldRev" : "_VjVClbW---"
}
Allow us currently to peruse the refreshed tune's ascribes −
127.0.0.1:8529@song_collection> db.songs.document('A_Man');
Yield
{
"_key" : "A_Man",
"_id" : "songs/A_Man",
"_rev" : "_VjVOcqe---",
"title" : "A Man's Best Friend",
"lyricist" : "Johnny Mercer",
"composer" : "Johnny Mercer",
"Year" : 1950,
"production" : "Top Banana"
}
An enormous report can be handily refreshed with the update work, particularly when the ascribes are not many.
Interestingly, the supplant capacity will cancel your information on utilizing it with a similar report.
127.0.0.1:8529@song_collection> db.songs.replace("songs/A_Man",{production:
"Top Banana"});
Allow us currently to check the melody we have recently refreshed with the accompanying line of code −
127.0.0.1:8529@song_collection> db.songs.document('A_Man');
Yield
{
"_key" : "A_Man",
"_id" : "songs/A_Man",
"_rev" : "_VjVRhOq---",
"production" : "Top Banana"
}
Presently, you can see that the archive no longer has the first information.
Instructions to Remove Documents
The eliminate work is utilized in blend with the archive handle to eliminate a record from an assortment −
127.0.0.1:8529@song_collection> db.songs.remove('A_Man');
Allow us currently to check the tune's ascribes we just eliminated by utilizing the accompanying line of code −
127.0.0.1:8529@song_collection> db.songs.document('A_Man');
We will get an exemption blunder like the accompanying as a yield −
JavaScript exception in file
'/usr/share/arangodb3/js/client/modules/@arangodb/arangosh.js' at 97,7:
ArangoError 1202: document not found
! throw error;
! ^
stacktrace: ArangoError: document not found
at Object.exports.checkRequestResult
(/usr/share/arangodb3/js/client/modules/@arangodb/arangosh.js:95:21)
at ArangoCollection.document
(/usr/share/arangodb3/js/client/modules/@arangodb/arango-collection.js:667:12)
at <shell command>:1:10