Giter VIP home page Giter VIP logo

Comments (6)

ra0o0f avatar ra0o0f commented on May 31, 2024

@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.

sithwin avatar sithwin commented on May 31, 2024

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.

ra0o0f avatar ra0o0f commented on May 31, 2024

@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.

sithwin avatar sithwin commented on May 31, 2024

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.

ra0o0f avatar ra0o0f commented on May 31, 2024

@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.

sithwin avatar sithwin commented on May 31, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.