Comments (6)
@sithwin if by Scalar you mean to return attributes of a document then you should use LINQ for this:
Assume you want to return ResourceName
attribute of Resource
collection:
string resourceName = db.Query<Resource>()
// with Where you could apply any condition
.Select(r => r.ResourceName)
.First();
If you want to check if a document has a attribute or not you could:
bool hasResourceName = db.Query<Resource>()
.Select(r => AQL.Has(r, "ResourceName"))
.First();
from arangoclient.net.
Hi @ra0o0f , thanks for your quick reply.
Any performance different between:
`bool has = _arangoDb.Query<CmsContentTypeView>()
.Where( r => r.Key == Id.ToString())
.Select(r => AQL.Has(r, "Id"))
.First();`
And
if (_arangoDb.Document<Resource>(Id) == null)
I think, first query returns only Id and Second has whole object.
Please advice!
Thanks.
from arangoclient.net.
@sithwin first query doe not return the id, it checks if document has Id
attribute or not. if you want to return it use:
string resourceName = db.Query<CmsContentTypeView>()
.Where( r => r.Key == Id.ToString())
.Select(r => r.Key)
.First();
About the performance you are right, _arangoDb.Document
will return the whole object and therefore it's slower.
@sithwin i'm not sure if i understand completely what you want to achieve, if you can explain it, i can show how to query it
from arangoclient.net.
Hi @ra0o0f ,
Firstly, I would like to make use of arangoDB key for better performance.
Secondly, I just want to check the again whether the data is successfully inserted. On the other hand, I created custom arrangoDb key before I inserted into database.
Right now, I used
if (_arangoDb.Document<Resource>(Id) == null)
to check the data is inserted or not. However, it returns the whole object. It is expensive.
I just want to check with the key whether it is exist or not..
I think, this is less expensive than my above "if" statement.
bool has = _arangoDb.Query<Resource>() .Where(r => r.Key == Id.ToString()) .Select(r => AQL.Has(r, r.Key)) .First();
Please advice what should be the best approach.
Thanks.
from arangoclient.net.
@sithwin now i understand what you want to do.
for checking if a document exists or not with LINQ(AQL), there is no need for AQL.Has
since it checks for attributes existence not the document, just get count and check if its zero or not
var count = db.Query<Resource>()
.Where(r => r.Key == Id.ToString())
.Count();
if(count!=0)
// then exists
There is another way to check for the document existence without loading it. it's not implemented yet. i will inform you as soon as its done
@sithwin note that ArangoDB has also Upsert
command which can insert/update a document if it exists or not in one request. this is usefull if you care about performance and consistency
from arangoclient.net.
Hi @ra0o0f ,
For now on, .Count()
can be solved my requirement.
Pls be inform once document existence method is available.
Thanks a lot!
from arangoclient.net.
Related Issues (20)
- ArangoServerException not throw when db unavailable HOT 2
- Thread safety HOT 7
- Confused with SystemDatabaseCredential HOT 5
- Custom Index HOT 6
- ByExampleAsync missing HOT 2
- Make ChangeCollectionPropertyForType public HOT 1
- Using LINQ query with Where performance HOT 1
- Error in generated AQL when upserting a generic document HOT 7
- ArangoServerException eats up all the useful information like status code and error number HOT 2
- Make collection name resolver more extensible HOT 2
- Annotating a property of type Guid as DocumentProperty.Key throws InvalidCastException HOT 2
- Support private setter
- CreateStatement<object> & Remove Vertex HOT 1
- Ternary operator support
- Global error handling policy
- Support for keyOptions: uuid
- Edge Document API not supported?
- Cannot Simply Connect to Server...... HOT 2
- Secure connection to ArangoDB
- Query directly within a collection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arangoclient.net.