[MarkLogic Dev General] Forests and Collections querying problem

Danny Sokolsky dsokolsky at marklogic.com
Sun Aug 10 00:47:02 PDT 2008


Hi Darren,

I'm afraid I gave you the wrong query to try.  It should be:

xdmp:describe(fn:collection("MDCOL")[1]/node())

Sorry about that...

Your query that ends with a slash ( / ) is a syntax error. You need to
specify a stem in after the slash.

-Danny

-----Original Message-----
From: general-bounces at developer.marklogic.com
[mailto:general-bounces at developer.marklogic.com] On Behalf Of Darren
Govoni
Sent: Saturday, August 09, 2008 4:01 PM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] Forests and Collections querying
problem

Colleen,
   Thanks for the tip. I am using XCC and the XML is in a String, not a
file. There is an XML declaration in the string so I assumed MarkLogic
could detect the format.

Nonetheless, I called ContentCreateOptions.setFormatXML() and passed the
options object to my Content object. I thought this would solve the
problem, but it didn't.

After adding my valid XML string successfully to my forest and
collection (unsure what format), Danny's xquery still indicates "not a
node".

cqsh> xdmp:describe(fn:collection("MDCOL")[1])/node();

if I do

cqsh> collection("MDCOL");

I get the document XML.

if I do

cqsh> collection("MDCOL")/;

I get errors. What is wrong here? I wasn't expecting this to be so
difficult. There is very little documentation in any of the guides on
working with collections by the way and many of the dev guide
suggestions in Xquery offer little clues how to do the same with XCC
in API mode.

thank you,
Darren


On Sat, 2008-08-09 at 08:35 -0700, Colleen Whitney wrote:
> Darren,
> 
> You'll either need to specify a document URI with an extension that
the server understands as associated with the XML format (like .xml), or
specify that format is XML as an option during document load.  Unknown
is treated as binary.
> 
> See sections 11.1 and 11.2 of the developer's guide
(http://developer.marklogic.com/pubs/3.2/books/dev_guide.pdf) for more
details, and look at the "Mimetypes" screen in the Admin interface for
mappings of file extensions to mimetypes and document formats.
> 
> --Coleen
> 
> -----Original Message-----
> From: general-bounces at developer.marklogic.com on behalf of Darren
Govoni
> Sent: Sat 8/9/2008 4:17 AM
> To: General Mark Logic Developer Discussion
> Subject: RE: [MarkLogic Dev General] Forests and Collections querying
problem
>  
> Hey Danny,
>    Thanks for getting back. I did download cq - its a great tool!
> Here's what I got from your query:
> 
> Message: XDMP-NOTANODE:
> xdmp:describe((collection("MDC"))[1])/child::node() --
> "doc("mde:mdc://e09bd84d-f43e-4e8e-b369-03e11633a0fd")" is
not
> a node
> 
> I presume then, my XML document I loaded is not stored as XML. A bit
of
> a surprise! How do I tell ML to store it as XML? 
> 
> Darren
> 
> On Fri, 2008-08-08 at 23:19 -0700, Danny Sokolsky wrote:
> > Hi Darren,
> > 
> > Are you sure the document was loaded as XML and not as text or
binary?
> > 
> > try:  xdmp:describe(fn:collection("MDCOL")[1])/node()
> > 
> > You might also want to get cq from the workshop on the developer
site.  It will make it easy to run queries against all of your
databases.
> > 
> > -Danny
> > 
> > 
> > -----Original Message-----
> > From: general-bounces at developer.marklogic.com on behalf of Darren
Govoni
> > Sent: Fri 8/8/2008 12:48 PM
> > To: General Mark Logic Developer Discussion
> > Subject: RE: [MarkLogic Dev General] Forests and Collections
querying problem
> >  
> > Danny,
> >    Thanks again for the tips. I was able to get the query to work.
> > 
> > ?for $doc in fn:collection(\"MDCOL\") return $doc
> > 
> > It returns a document in the collection. But when I try to use
> > namespaces to retrieve by element, I get nothing.
> > 
> > declare namespace mde="http://metadata.dod.mil/mdr/ns/MDE/1.0/"
> > ?for $doc in fn:collection(\"MDCOL\")/mde:MyElement return $doc
> > 
> > According to the loaded XML document, this should return a document
> > since /MyElement, the root element, is in the mde declared namespace
> > (xmlns="?http://metadata.dod.mil/mdr/ns/MDE/1.0/")
> > 
> > Am I missing something?
> > 
> > Darren
> > 
> > On Fri, 2008-08-08 at 11:07 -0700, Danny Sokolsky wrote:
> > > Someone else will have to comment on your Java code, as I don't
know
> > > Java too well, I am afraid (although I don't see where your
options
> > > variable comes from in your load code--looks like it should be
> > > createOptions  ??).
> > > 
> > > BTW, there are two methods on ContentCreateOptions called
setPlaceKeys
> > > that you can use to set the forest when creating content.
> > > 
> > > Also, you might look at RecordLoader in the workshop section of
the
> > > developer.marklogic.com site
(http://developer.marklogic.com/code/).
> > > 
> > > -Danny
> > > 
> > > -----Original Message-----
> > > From: general-bounces at developer.marklogic.com
> > > [mailto:general-bounces at developer.marklogic.com] On Behalf Of
Darren
> > > Govoni
> > > Sent: Friday, August 08, 2008 10:43 AM
> > > To: General Mark Logic Developer Discussion
> > > Subject: RE: [MarkLogic Dev General] Forests and Collections
querying
> > > problem
> > > 
> > > Hi Danny,
> > >    Thanks for the rapid response! Well, I'm using XCC and the
> > > documentation is rather thin on these details. Here is how I am
loading
> > > it.
> > > 
> > > ===========================
> > > 
> > >             ContentCreateOptions createOptions = new
> > > ContentCreateOptions();
> > >             String collection = "MDCOL";
> > > 
> > >             String collections[] = {collection};
> > >             createOptions.setCollections(collections);
> > >             
> > >             Content contents = ContentFactory.newContent(id,
xmlStr,
> > > options);
> > > 
> > >             session.insertContent(contents);
> > > 
> > >             System.out.println("Inserted: " + xmlStr);
> > > 
> > > I try to read it this way:
> > > ===========================
> > > 
> > > 		RequestOptions options = new RequestOptions();
> > >                 
> > > 		options.setCacheResult (false);
> > > 
> > > 		Request request = session.newAdhocQuery ("for $doc in
> > > fn:collection(\"MDCOL\") return $doc",options);
> > > 		
> > > 		ResultSequence rs = session.submitRequest (request);
> > > 
> > > What is odd to me is there is no way to specify a Forest with XCC
(that
> > > I can tell) as the XQuery docs describe - for loading it. I saw
the
> > > content metadata object, but no docs on it I could find.
> > > 
> > > However, the query is simply enough and the session URI points to
the
> > > containing MDE database where the forests reside. So I'm stuck!
> > > 
> > > Darren
> > > 
> > > On Fri, 2008-08-08 at 10:32 -0700, Danny Sokolsky wrote:
> > > > Hi Darren,
> > > > 
> > > > When you load documents into a database, unless you explicitly
state
> > > the
> > > > forest to which it is loaded (with a forest placement key), the
system
> > > > will automatically choose a forest for each document during the
load
> > > > process (this explains why you see "the forests randomly
increment
> > > their
> > > > document count").
> > > > 
> > > > How did these documents get in the MDCOL collection?  You can do
that
> > > > upon load or after load with xdmp:document-set-collections.  If
the
> > > > following query against the MDE database returns 0:
> > > > 
> > > > xdmp:estimate(fn:collection("MDCOL"))
> > > > 
> > > > it means there are no documents in that collection named MDCOL.
Your
> > > > query seems like it should return all the document in the
collection
> > > > (although I am not good at java string escaping...).  Maybe
there are
> > > > actually no documents in that collection?  Maybe the name was
> > > > misspelled, either on load or on query?
> > > > 
> > > > -Danny
> > > > 
> > > > -----Original Message-----
> > > > From: general-bounces at developer.marklogic.com
> > > > [mailto:general-bounces at developer.marklogic.com] On Behalf Of
Darren
> > > > Govoni
> > > > Sent: Friday, August 08, 2008 10:04 AM
> > > > To: General Mark Logic Developer Discussion
> > > > Subject: [MarkLogic Dev General] Forests and Collections
querying
> > > > problem
> > > > 
> > > > Hi,
> > > >   I want to store a document in a forest and collection. The
document
> > > is
> > > > part of a collection "MDCOL". I currently have 2 forests
associated
> > > with
> > > > my database MDE - they are "MDR" and "MDC". When I connect
through XCC
> > > > (to the MDE database) and store a document labeled for the "MDC"
> > > > collection. I see the forests randomly increment their document
count.
> > > > Sometimes its the MDR forest, sometimes the MDC. Furthermore,
when I
> > > > query for all documents in the MDCOL collection, I get none.
> > > > 
> > > > Request request = session.newAdhocQuery ("for $doc in
> > > > fn:collection(\"MDCOL\") return $doc",options);
> > > > 
> > > > The documentation didn't explain querying collections well
enough 
> > > > to solve this in short period. Can someone offer a tip?
> > > > 
> > > > thank you,
> > > > Darren
> > > > 
> > > > 
> > > > _______________________________________________
> > > > General mailing list
> > > > General at developer.marklogic.com
> > > > http://xqzone.com/mailman/listinfo/general
> > > > _______________________________________________
> > > > General mailing list
> > > > General at developer.marklogic.com
> > > > http://xqzone.com/mailman/listinfo/general
> > > 
> > > _______________________________________________
> > > General mailing list
> > > General at developer.marklogic.com
> > > http://xqzone.com/mailman/listinfo/general
> > > _______________________________________________
> > > General mailing list
> > > General at developer.marklogic.com
> > > http://xqzone.com/mailman/listinfo/general
> > 
> > _______________________________________________
> > General mailing list
> > General at developer.marklogic.com
> > http://xqzone.com/mailman/listinfo/general
> > 
> > _______________________________________________
> > General mailing list
> > General at developer.marklogic.com
> > http://xqzone.com/mailman/listinfo/general
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general

_______________________________________________
General mailing list
General at developer.marklogic.com
http://xqzone.com/mailman/listinfo/general


More information about the General mailing list