How to create MongoDB Virtual Graph mapping for SQL equivalent "WHERE" & "LIMIT" clause

Hello Stardog Team,

I would need help in writing a MongoDB JSON virtual graph mapping for the corresponding SQL virtual mapping as shared below, with the focus on replicating the "WHERE" and "LIMIT" clauses in MongoDB mapping syntax. The requirement from this kind of mapping is that we pick a specific subset of data from our MongoDB data source based on the filters and then use it to enrich our knowledge graph -

MAPPING :AlbumMapping
FROM SQL {
  SELECT * 
  FROM Album
  **WHERE** artist = 'John_Lennon'
  **LIMIT** 5
}
TO {
  ?album a :Album ;
           :name ?name ;
           :artist ?artist ;
           :date ?release_date 
} 
WHERE {
  BIND(template("http://stardog.com/tutorial/Album{id}") AS ?album)
  BIND(template("http://stardog.com/tutorial/Artist{artist}") AS ?artist)
}

Thanks & Regards,
Ashish

Hi Ashish,

Mapping to MongoDB does not support any kind of WHERE or LIMIT clauses. Each mapping must have a FROM JSON clause where you describe the schema of a single collection. Multiple mappings can be included in the same SMS file, separated by semicolons. Each mapping is one-to-one - any filtering or limits must be applied in your SPARQL query. See here for an example mapping. If you have some standard filters that you always want to apply, you might consider creating a stored query and using it like a stored procedure.

-Paul

Thank you Paul for your answer. I have a few follow-up questions on this;

Currently, I'm materializing the virtual graph into stardog database using the below SPARQL update query in Workspace -
ADD <virtual://mongodb_vg> TO <mongodb:materialized_named_graph>

My question is - using the solution you provided in the last reply, can I use that filters applied SPARQL query while materializing that virtual graph? In short, is it possible to use stored query along with sparql update queries?
The requirement is to materialize a specific subset of documents from our MongoDB collection.

Looking forward to hearing from you. Thank you

Regards,
Ashish

Yes, your query is a shortcut for this more general query:

INSERT {
  GRAPH <mongodb:materialized_named_graph> {
    ?s ?p ?o
  }
}
WHERE {
  GRAPH <virtual://mongodb_vg> {
    # Whatever query you like (though the vars here must match the vars used above)
    ?s ?p ?o
    # FILTER (?o = "for example, a filter like this")
  }
}

-Paul