node.jsgremlingraph-databasesgqlquery

The code below shows the extracting data from graph db using node js. the data is extracting fine but when I use filter (where) it gives empty result


    g.v()
  .has('label','Event')
  .not(has('active',false)).as('Event').order().by('createdTimestamp', decr)
  .project('label','event', 'user')
  .by(constant('Livestream'))
  .by(
    __.select('Event')
    .project('id', 'label', 'name', 'cover', 'description', 'allowComments', 'active', 'hashtags', 'partitionValue', 'userId', 'createdTimestamp', 'createdDate')
  .by('id').by('label').by('name').by('cover').by('description').by('allowComments')
  .by(
    coalesce(
      values('active'),
      constant(true)
    )
  )
  .by('hashtags')
  .by('partitionValue').by('userId').by('createdTimestamp').by('createdDate')
  )
  .by(
    __.in('USERcreatedEVENT')
    .project('id', 'privacy', 'label', 'email', 'username', 'name',  'displayPic')
    .by('id').by('privacy').by('label').by('email').by('username').by('name').by('displayPic')
  )
.where(select('privacy').is(eq('PUBLIC')))

This is the code from where I need data by filtering on the basis of user privacy. I am doing in this way but it is not working can you help me in this regard. The code below shows the extracting data from graph db using node js. the data is extracting fine but when I use filter (where) it gives empty result. If you still need some information do ask me.


Solution

  • If I get it right, then you are trying to filter the results where privacy property of the in vertex is equal to public.

    I can tell you why this query is returning empty results. Because the privacy label is not set and when you write select('privacy'), there is no such label and hence equality comparison with non existing label filters out everything.

    you can try :

    g.V().
      has('label', 'Event').
      not(has('active', false)).as('Event').
      order().by('createdTimestamp', decr).
      project('label', 'event', 'user').
        by(constant('Livestream')).
        by(
          select('Event').
          project( 'id', 'label', 'name', 'cover', 'description', 'allowComments',
            'active', 'hashtags', 'partitionValue', 'userId', 'createdTimestamp',
            'createdDate').
            by('id').  by('label').  by('name').  by('cover').  by('description').
            by('allowComments').  by(coalesce(values('active'), constant(true))).
            by('hashtags').  by('partitionValue').  by('userId').  by('createdTimestamp').
            by('createdDate')).
        by(
          in('USERcreatedEVENT').
          project( 'id', 'privacy', 'label', 'email', 'username', 'name', 'displayPic').
            by('id').  by('privacy').  by('label').  by('email').  by('username').
            by('name').  by('displayPic')).
      where(select('Event').in('USERcreatedEVENT').has('privacy', 'PUBLIC'))