Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate documents getting inserted in edge collection

I am using node driver version 6 of arangodb to insert relations between two vertices as follows.

db.collection("starks").save({ 
    _from: "Starks/Lyanna-Stark", 
    _to: "Starks/Ned-Stark", 
    type: "married" 
});

This inserts relation married between Starks/Lyanna-Stark and Starks/Ned-Stark into the database. But when I run this query twice, it is inserting it two times with different relation key. I want to avoid this as only one entry should be present for a single relation. How can I achieve this ?

like image 213
Dipti Avatar asked Aug 18 '18 13:08

Dipti


People also ask

How to fix Microsoft Edge favorites folder duplicate?

\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\AC\MicrosoftEdge\User\Default\Favorites If you can see the duplicates for the favorites folder, then you can delete to merge the favorites together. If the favorites folders is not duplicate, then try clearing the cache and cookies of the Microsoft Edge browser and check if it helps.

How do I edit or delete a collection in Microsoft Edge?

If you want to edit the name of a collection, or otherwise delete it entirely, right-click on the entry in the main Collections menu. From here, click “Edit Collection” to rename it or “Delete Collection” to delete the collection entirely. If you delete an Edge collection by accident, press the “Undo” button to reverse the action.

How to create a collection in Edge browser?

1 Creating New Microsoft Edge Collections. The Collections feature appears as an icon in the top-right corner of the Microsoft Edge window, between the favorites and user profile icons. 2 Adding Notes and Links to an Edge Collection. ... 3 Editing or Deleting Saved Notes or Pages. ... 4 Switching Between Collections. ...

How do I add a link to a Microsoft Edge collection?

To add a link to the web page you’re currently on to a Microsoft Edge collection, click the “Add Current Page” option in the Collections feature menu. To add a note, click the New Note button to the right of the “Add Current Page” link. This will bring up a note box with formatting options.


1 Answers

Just create a unique index for all the relations that you are creating. For example, if the name of your relation collection is relations, then run this query to make the combination of "_from", "_to", "type" as unique

db.relations.ensureIndex({ 
    type: "hash", 
    fields: [ "_from", "_to", "type" ], 
    unique: true 
});

Here is the link for reference https://docs.arangodb.com/3.0/Manual/Indexing/Hash.html#ensure-uniqueness-of-relations-in-edge-collections

like image 87
molecule Avatar answered Oct 06 '22 00:10

molecule