deleting documents using X-Query

Hi

I am developing a system where I need to have always X documents in a collection. Everytime I will insert new data, it will be as a new document. Thus I need to delete a document and insert the new one. How can I construct the XQuery to remove the oldest document to get X-1 docs before inserting the new document? Till now I managed to delete all the documents having a path /x/y from a specified collection as follows:

update for $doc in input()
where $doc/x/y
do delete $doc

However, I did not find a way to limit the deletion to the oldest one.

Brian

Hi Brian,

I do not have a solution but a hint: use tf:containsText (see docu). It gives you the date and time of the last modification of any document.

In a query something like

declare namespace tf=“http://namespaces.softwareag.com/tamino/TaminoFunction
for $p …

return


{tf:getLastModified(xf:root($p))}

)
sort by ( . descending)

(This query returned some data for me with newest first. Handy)

happy trying,

Timm



Hi,

How do you delete whole documents? If I try an update delete input()/document there is an Exception telling me that the result isn’t wellformed.
So the question is, how do I delete an document using XQuery?

bye
Dirk


Mail: dirk.kaspar[at]pansoft.de
Web: www.pansoft.de
Tel.: +49 (0)721 62532 - 16
Fax: +49 (0)721 62532 - 44

PANSOFT GmbH
Tullastr. 28
76131 Karlsruhe

PANSOFT - Open Source of course!

Wollen Sie mehr

Hello Dirk,

Using XQuery-Update must result in a wellformed document – so deleting the entire document cannot be done using XQuery. To delete entire documents use the _delete command with a valid XPath, e.g.

_delete=document

rather than

_xquery=update delete input()/document

Hope this helps.

Stuart Fyffe-Collins
Software AG (UK) Ltd.

Hi Stuart,

Thanks for your quick answer. But I’ve got an other problem with the delete:
I’d like to delete all Documents with an Datefield older than an given Date. In an Xquery I could formulate an query for that like

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"<BR>ceservice/jaxb/persistenceobjects"
declare namespace xs = “XML Schema
for $q in input()/document[@letzteaenderung < xs:dateTime(“2003-10-29T10:31:30.030+01:00”)]
return {$q}

But how could I express the Date in an XPath?

Bye
Dirk


Mail: dirk.kaspar[at]pansoft.de
Web: www.pansoft.de
Tel.: +49 (0)721 62532 - 16
Fax: +49 (0)721 62532 - 44

PANSOFT GmbH
Tullastr. 28
76131 Karlsruhe

PANSOFT - Open Source of course!

Wollen Sie mehr

Hello Dirk,

With X-Query (required for _delete) you cannot search using last modified date. So the described scenario can only be done programmatically, for example using the Tamino Java API.

HTH.

Stuart Fyffe-Collins
Software AG (UK) Ltd.

OK, Thanks for your Help.

I’ve found an solution thats working for me :slight_smile:

Bye
Dirk


Mail: dirk.kaspar[at]pansoft.de
Web: www.pansoft.de
Tel.: +49 (0)721 62532 - 16
Fax: +49 (0)721 62532 - 44

PANSOFT GmbH
Tullastr. 28
76131 Karlsruhe

PANSOFT - Open Source of course!

Wollen Sie mehr