Retrieving a Single Record from a Collection

Learn how to query and retrieve a single record directly from a collection using Corvid (a.k.a. Wix Code). 

​This example shows you how to retrieve a single shape record from a collection called #Shapes and displays the colour of the shape record found. Try the example below.

Try it!
iptSearch
Type a shape to begin!
#txtMessage
Shape
Colour
Rectangle
Green
Square
Green
Triangle
Red
Circle
Red
Triangle
Red
Rectangle
Green
Circle
Blue
Square
Green
Square
Red
Square
Red
Circle
Red
Triangle
Red
Circle
Blue
Square
Green
Rectangle
Green
Rectangle
Green
Triangle
Red
Circle
Blue
Square
Green
Circle
Red
Square
Red
Circle
Red
Rectangle
Green
Square
Green
Circle
Blue
Triangle
Red
Triangle
Red
Rectangle
Green
Circle
Blue
Square
Green
Square
Green
Triangle
Red
Triangle
Blue
Circle
Blue
Triangle
Green
Square
Red
Circle
Red
Circle
Red
Square
Green
Circle
Blue
Triangle
Red
Rectangle
Green
Rectangle
Green
Triangle
Red
Square
Green
Circle
Blue
Square
Green
Triangle
Red
Circle
Blue
Rectangle
Green
Circle
Red
Circle
Red

Add an onKeyPress event listener to the #iptSearch text box. It will pass the desired shape entered to the findShape function after a two second delay to ensure the use has finished typing. The findShape function executes a wixData.query on the #Shapes collection. If the desired shape is not found, a message is sent to #txtMessage advising the user. If the desired shape is found, then the colour is retrieved from the record and displayed to the user in #txtMessage.

 

The toTitleCase function converts the users shape input to title or proper case, which matches the case in the #Shapes collection - as the wixData.query function is case sensitive.

Page Code

Please wait ...
Disclaimer: To the best of our knowledge, this code works for its stipulated purpose. If you find an error in our code, or know of a better way to achieve the same result - please contact us! All our code snippets come with full support to help you implement them on your own website - simply contact us for help.