ArangoDB is a hybrid (document and graph) database. Its positive aspects include:
- powerful and convenient query language AQL
- JOIN (even more powerful than relational databases)
- replication and sharding
- ACID (works in the cluster only in the paid version)
Less essential, but no less convenient features:
- fuzzy search
- Foxx microservices engine built into the database
- work in the subscription mode for changes in the database
In fairness, I will also note the disadvantages:
- no ODM
- low popularity (in comparison with MongoDB, for example)
After analyzing the capabilities of ArangoDB and, in particular, after overcoming the shortcomings in the latest versions (such as a sharp drop in performance when the size of the collection of available RAM is exceeded) and the emergence of new features (such as fuzzy search), it is time to test in a real application.
AQL (ArangoDB Query Language) capabilities
One of the main questions that worried me was whether the expressiveness of AQL would be sufficient to execute the full range of queries in a real application. And will work without ORM / ODM be comfortable enough.
There are several ways in ArangoDB to query data. There is an object-oriented API familiar to those who work with MongoDB, but this method is considered obsolete in ArangoDB and the main emphasis is on AQL queries.
The simplest query for one collection looks like this:
db.query({
query: `for doc in managers
filter doc.role == @role
sort doc.@field @order
limit @page * @perPage, @perPage
return doc`,
bindVars: { role, page, perPage, field, order },
});
, FOR, , , , role .
, . mongoose (MongoDB) populate(). ArangoDB AQL:
db.query({
query: `
for mall in malls
for city in cities
filter mall.cityId == city._key
return merge(mall, { city })
`,
bindVars: { },
});
INNER JOIN. , city , , SQL.
LEFT JOIN β LET:
db.query({
query: `
for city in cities
let malls=(
for mall in malls
filter mall.cityId==city._key
return mall
)
return merge(city, {malls})`,
bindVars: { },
});
malls array null. , LEFT JOIN SQL β , city, mall. mall . , . "" , SQL, , .
, . , , , , , SQL. - NoSQL , .
- ArangoDB . : _from _to. , . .
- . , update . . , .
: , . , Elacticsearch. . -, Elasticsearch. , , . , -, Elasticsearch , .
ArangoDB SEARCH VIEW :
await db.createAnalyzer('fuzzy_brand_search_bigram', {
type: 'ngram',
properties: { min: 2, max: 2, preserveOriginal: true },
features: ['position', 'frequency', 'norm'],
});
await db.createView('brandSearch', {
links: {
brands: {
includeAllFields: true,
analyzers: ['fuzzy_brand_search_bigram'],
},
},
});
:
db.query({
query: `
for brand in brandSearch
search NGRAM_MATCH(
brand.name,
@brandName,
0.4,
'fuzzy_brand_search_bigram'
)
filter brand.mallId == @mallId
return brand `,
bindVars: { mallId, brandName },
});
ODM?
, , , AQL, . , Sequelize (ORM ), - RAW .
, , , ODM. , ODM ArangoDB. ODM . , ODM , . , , , .
, , . . - PATCH , , , . . , -, . issue . , , . , . .
In my article, I described and implemented my library. I used it in a real project. Of course, there were moments of stress when it turned out that the capabilities of this library were not enough. But they were mostly resolved. So I still invite those who wish to promote the ArangoDB technology to cooperation.
apapacy@gmail.com
March 15, 2021